Cod sursa(job #1725523)

Utilizator SzymonSidorSzymonSidor SzymonSidor Data 5 iulie 2016 20:16:15
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <algorithm>
#include <iostream>
#include <fstream>
#include <climits>

using namespace std;

int n;
int dist[105][105];

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

    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            cin >> dist[i][j];
            if (!dist[i][j] && i != j)
                dist[i][j] = 1001;
        }

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

    for (int i = 0; i < n; cout << "\n", i++)
        for (int j = 0; j < n; j++)
            cout << (dist[i][j] > 1000? 0 : dist[i][j]) << " ";

    return 0;
}