UVA Solution 423 - MPI Maelstrom - Solution in ANSI C - Volume 4 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Tuesday, May 9, 2017

UVA Solution 423 - MPI Maelstrom - Solution in ANSI C - Volume 4

UVA Solution 423 - MPI Maelstrom - Solution in ANSI C - Volume 4


UVA Online Judge Solution 423 - MPI Maelstrom | Volume 4
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=364

Problem Name: 423 - MPI Maelstrom
Problem Number : UVA - 423 - MPI Maelstrom
Online Judge : UVA Online Judge Solution
Volume: 4
Solution Language : C, C plus plus

UVA Solution 423 - MPI Maelstrom - Solution in ANSI C - Volume 4

UVA Solution 423 - MPI Maelstrom Code in ANSI C:


#include <stdio.h>
#define oo 0xfffffff
int main() {
    int n, g[105][105], i, j, k, x;
    while(scanf("%d", &n) == 1) {
        for(i = 0; i < n; i++)
            g[i][i] = oo;
        for(i = 1; i < n; i++) {
            for(j = 0; j < i; j++) {
                if(scanf("%d", &x) == 1)
                    g[i][j] = g[j][i] = x;
                else
                    g[i][j] = g[j][i] = oo, scanf("%*c");
            }
        }
        for(k = 0; k < n; k++)
            for(i = 0; i < n; i++)
                for(j = 0; j < n; j++)
                    if(g[i][j] > g[i][k]+g[k][j])
                        g[i][j] = g[i][k]+g[k][j];
        int res = 0;
        for(i = 1; i < n; i++)
            if(g[0][i] > res)
                res = g[0][i];
        printf("%d\n", res);
    }
    return 0;
}

No comments:

Post a Comment