Cod sursa(job #1725520)

Utilizator SzymonSidorSzymonSidor SzymonSidor Data 5 iulie 2016 20:10:04
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <algorithm>
#include <iostream>
#include <fstream>

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]);

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

    return 0;
}