Cod sursa(job #2211342)

Utilizator ContDeRacistAliniateEBlat ContDeRacist Data 9 iunie 2018 22:35:11
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include <fstream>

using namespace std;

ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");

int d[105][105];

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            cin >> d[i][j];
        }
    }
    for (int k = 1; k <= n; ++k) {
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                if (i != j && d[i][k] && d[k][j] && (d[i][j] > d[i][k] + d[k][j] || !d[i][j])) {
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            cout << d[i][j] << " ";
        }
        cout << "\n";
    }
    return 0;
}