Cod sursa(job #2856246)

Utilizator cezar.balutaCezar Baluta cezar.baluta Data 23 februarie 2022 16:52:22
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.31 kb
/*
                         __
                   _.--""  |
    .----.     _.-'   |/\| |.--.
    |    |__.-'   _________|  |_)  _______________
    |  .-""-.""""" ___,    `----'"))   __   .-""-.""""--._
    '-' ,--. `    |Cezar| .---.       |:.| ' ,--. `      _`.
     ( (    ) ) __|  7  |__\\|// _..-- \/ ( (    ) )--._".-.
      . `--' ;\__________________..--------. `--' ;--------'
       `-..-'                               `-..-'
*/
#include <iostream>
#include <fstream>
using namespace std;

const int N = 1e2 + 5;
const int INF = (1<<28);
int mat[N][N];

int main() {
    ifstream in("royfloyd.in");
    ofstream out("royfloyd.out");
    int n;
    in>>n;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            in>>mat[i][j];
            if(i != j && mat[i][j] == 0)
                mat[i][j] = INF;
        }
    }
    for(int k = 1;k <= n; k++){
        for(int i = 1;i <= n;i++){
            for(int j = 1;j <= n;j++){
                mat[i][j] = (mat[i][k] + mat[k][j])*(mat[i][j] > (mat[i][k] + mat[k][j])) +  mat[i][j]*(mat[i][j] <=( mat[i][k] + mat[k][j]));
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(mat[i][j] == INF)
                out<<0<<' ';
            else out<<mat[i][j]<<' ';
        }
        out<<'\n';
    }
    return 0;
}