Cod sursa(job #1818998)

Utilizator zeboftwAlex Mocanu zeboftw Data 29 noiembrie 2016 23:54:44
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>

using namespace std;

ifstream fin ("royfloyd.in");
ofstream fout ("royfloyd.out");

int dist[101][101];

int main()
{
    int n;
    fin >> n;
    for (int i=1; i <= n; i++)
        for (int j=1; j <= n; j++)
            fin >> dist[i][j];

    for (int k=1; k <= n; k++)
        for (int i=1; i <= n; i++)
            for (int j=1; j <= n; j++)
                if (dist[i][k] && dist[k][j] && (dist[i][j] > dist[i][k] + dist[k][j] || !dist[i][j]) && i != j) dist[i][j] = dist[i][k] + dist[k][j];

    for (int i=1; i <= n; i++) {
        for (int j=1; j <= n; j++)
            fout << dist[i][j] << ' ';
        fout << '\n';
    }
    return 0;
}