Cod sursa(job #3197433)

Utilizator victor_gabrielVictor Tene victor_gabriel Data 26 ianuarie 2024 20:04:51
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>
#include <climits>

using namespace std;

ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");

const int DIM = 110;

int n;
int mat[DIM][DIM];

int main() {
    fin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            fin >> mat[i][j];
        }
    }

    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                if (mat[i][j] > mat[i][k] + mat[k][j])
                    mat[i][j] = mat[i][k] + mat[k][j];

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++)
            fout << mat[i][j] << ' ';
        fout << '\n';
    }

    return 0;
}