Cod sursa(job #3192655)

Utilizator v_mateiVatamanu Matei v_matei Data 13 ianuarie 2024 09:35:19
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
#include <bits/stdc++.h>

using namespace std;

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

int n;

int c[107][107];

int main(){
    fin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            fin >> c[i][j];
            if(c[i][j] == 0){
                c[i][j] == 1000000;
            }
        }
    }

    for(int z = 1; z <= n; z++){
        for(int x = 1; x <= n; x++){
            for(int y = 1; y <= n; y++){
                if(c[x][z] + c[z][y] < c[x][y]){
                    c[x][y] = c[x][z] + c[z][y];
                }
            }
        }
    }

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(c[i][j] != INT_MAX) fout << c[i][j] << " ";
            else fout << 0 << " ";
        }
        fout << endl;
    }

    return 0;
}