Cod sursa(job #3323173)

Utilizator oliv_1Bostinescu Octavian oliv_1 Data 17 noiembrie 2025 14:10:00
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>

using namespace std;
int dist[1005][1005];
int main()
{
    ifstream cin("royfloyd.in");
    ofstream cin("royfloyd.out");
 int n,a;
 cin>>n;
 for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
 {
     cin>>a;
     if(i!=j)
     {
         if(a==0)
            dist[i][j]=10e6;
         else
            dist[i][j]=a;
     }
 }
 for(int k=1;k<=n;k++)
 {
     for(int i=1;i<=n;i++)
     {
         for(int j=1;j<=n;j++)
            dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
     }
 }
 for(int i=1;i<=n;i++)
 {
     for(int j=1;j<=n;j++)
     {
         if(dist[i][j]==10e6)
            cout<<0<<" ";
         else
            cout<<dist[i][j]<<" ";
     }
     cout<<'\n';
 }
    return 0;
}