Cod sursa(job #1650912)

Utilizator ioan.veveraIoan Vevera ioan.vevera Data 11 martie 2016 21:27:51
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
#include <fstream>

using namespace std;
ifstream fin ("royfloyd.in");
ofstream fout ("royfloyd.out");
int n,a[101][101];
int main()
{
    fin>>n;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++) fin>>a[i][j];
    for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)

        if(i!=j && i!=k && k!=j)
            if(a[i][k]&&a[k][j])
        if(a[i][k]+a[k][j]<=a[i][j] || !a[i][j]) a[i][j]=a[i][k]+a[k][j];
    for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++) fout<<a[i][j]<<' ';fout<<endl;}
    return 0;
}