Cod sursa(job #2643674)

Utilizator De_Azi_Ne_DopamAlex Ardelean De_Azi_Ne_Dopam Data 20 august 2020 20:33:13
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <bits/stdc++.h>
using namespace std;
int d[101][101];
int main()
{
#ifdef HOME
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
#endif // HOME
#ifndef HOME
    freopen("euclid3.in","r",stdin);
    freopen("euclid3.out","w",stdout);
#endif // HOME
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i,j;
    cin>>n;
    for(i=1; i<=n; i++)
        for(j=1; j<=n; j++)
            cin>>d[i][j];
    for(int k=1; k<=n; k++)
        for(i=1; i<=n; i++)
            for(j=1; j<=n; j++)
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
            cout<<d[i][j]<<" ";
        cout<<'\n';
    }
    return 0;
}