Cod sursa(job #2801421)

Utilizator AlexNicuNicu Alexandru AlexNicu Data 16 noiembrie 2021 11:03:21
Problema Floyd-Warshall/Roy-Floyd Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <fstream>

using namespace std;

#define NMAX 1000

int dist[NMAX][NMAX];

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

int main() {
    int n, i, j, k;
    cin >> n;
    for ( i = 0; i < n; i++ ) {
        for ( j = 0; j < n; j++ )
            cin >> dist[i][j];
    }
    for ( i = 0; i < n; i++ ) {
        for ( j = 0; j < n; j++ ) {
            for ( k = 0; k < n; k++ ) {
                if ( dist[i][k] + dist[k][j] < dist[i][j] )
                    dist[i][j] = dist[i][k] + dist[k][j];
            }
        }
    }
    for ( i = 0; i < n; i++ ) {
        for ( j = 0; j < n; j++ )
            cout << dist[i][j] << " ";
        cout << "\n";
    }
    return 0;
}