Cod sursa(job #1725522)

Utilizator SzymonSidorSzymonSidor SzymonSidor Data 5 iulie 2016 20:12:26
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 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];

    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])? dist[i][k] + dist[k][j] : 1001);

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

    return 0;
}