Cod sursa(job #2639679)

Utilizator Iustin01Isciuc Iustin - Constantin Iustin01 Data 3 august 2020 14:26:57
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>
#define oo 1500
using namespace std;

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

int n, mat[105][105];

int main(){
    in>>n;
    for(int i = 1; i <= n; i++)
    for(int j = 1; j <= n; j++){
        in>>mat[i][j];
        if(!mat[i][j])
            mat[i][j] = oo;
    }

 for(int k = 1; k <= n; k++)
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
                if(i != j && 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++, out<<"\n")
    for(int j = 1; j <= n; j++)
        out<<(mat[i][j] == oo ? 0 : mat[i][j])<<" ";
}