Cod sursa(job #1919648)

Utilizator KronSabau Valeriu Kron Data 9 martie 2017 20:22:28
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int cost[110][110],n;
int main()
{
    f >>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++){
            f >> cost[i][j];
            if(!cost[i][j])
                cost[i][j]==INT_MAX/2;
        }
    for(int i=1;i<=n;i++)
        cost[i][i]=0;

    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                    cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)
            g << cost[i][j] << " ";
            g << "\n";
        }

    return 0;
}