Cod sursa(job #2738855)

Utilizator MoldovanAndrei1Moldovan Andrei MoldovanAndrei1 Data 6 aprilie 2021 14:25:48
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 105;
int c[NMAX][NMAX];
int main()
{
    freopen("royfloyd.in","r",stdin);
    freopen("royfloyd.out","w",stdout);
    int n , i , j , k ;
    scanf("%d",&n);
    for(i = 1 ; i <= n ; i++)
        for(j = 1 ; j <= n ;j++)
        {
            scanf("%d",&c[i][j]);
            if(c[i][j] == 0) c[i][j] = 100000000;
        }

         for(k = 1 ; k <= n ; k++)
            for(i = 1; i <= n ; i++)
        for(j = 1 ; j <= n ;j++)
          if(c[i][j] > c[i][k]+c[k][j])c[i][j]=c[i][k]+c[k][j];
    for(i = 1 ; i <= n ; i++)
    {
        for(j = 1 ; j <= n ;j++)
            if(c[i][j]!=100000000&& i!=j)printf("%d ",c[i][j]);
            else
                printf("0 ");
        printf("\n");
    }
    return 0;
}