Cod sursa(job #2964893)

Utilizator SebytomitaTomita Sebastian Sebytomita Data 14 ianuarie 2023 09:30:03
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include <fstream>
#define NMAX 104
#define INF 99999999
using namespace std;
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int n,i,j,x,y,z;
int c[NMAX][NMAX];
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            cin>>c[i][j];
            if(c[i][j]==0)
                c[i][j]=INF;
            if(i==j)
                c[i][j]=0;
        }
    }
    for(z=1;z<=n;z++)
    {
        for(x=1;x<=n;x++)
        {
            for(y=1;y<=n;y++)
            {
                c[x][y]=min(c[x][z]+c[z][y],c[x][y]);
            }
        }
    }

    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
                cout<<c[i][j]<<' ';
        }
        cout<<'\n';
    }
    return 0;
}