Cod sursa(job #3284783)

Utilizator Dia3141Costea Diana Stefania Dia3141 Data 12 martie 2025 10:44:15
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <fstream>
using namespace std;
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int a[101][101],n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            cin>>a[i][j];
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++)
            if(i!=k)
                for(int j=1;j<=n;j++)
                    if(j!=k&&i!=j&&a[i][k]!=0&&a[k][j]!=0&&(a[i][j]==0||a[i][j]>a[i][k]+a[k][j]))
                        a[i][j]=a[i][k]+a[k][j];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)
            cout<<a[i][j]<<" ";
        cout<<'\n';
    }
    return 0;
}