Cod sursa(job #3029926)

Utilizator Glue02Tudorescu Ioan Daniel Glue02 Data 17 martie 2023 11:41:57
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <fstream>
#define INF 100000001
using namespace std;

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