Cod sursa(job #2206471)

Utilizator andrew_assassin789Andrei Manea andrew_assassin789 Data 22 mai 2018 19:03:43
Problema Floyd-Warshall/Roy-Floyd Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <fstream>
#include <climits>
#define nmax 2005
using namespace std;
int a[nmax][nmax];
int t[nmax][nmax];
int main()
{
    ifstream fin("royfloyd.in");
    ofstream fout("royfloyd.out");
    int n,m,i,x,y,j,k,cost;
    fin>>n;
    for (i=1;i<=n;i++)
        for (j=1;j<=n;j++)
        {
            fin>>a[i][j];
            if (i!=j && a[i][j]==0)
            {
                a[i][j]=INT_MAX;
            }
        }
    for (k=1;k<=n;k++)
        for (i=1;i<=n;i++)
            for (j=1;j<=n;j++)
            if (a[i][j]>a[i][k]+a[k][j])
            {
                a[i][j]=a[i][k]+a[k][j];
                t[i][j]=k;
            }
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
        {
            if (a[i][j]==INT_MAX)
                a[i][j]=0;
            fout<<a[i][j]<<' ';
        }
        fout<<'\n';
    }
    fin.close();
    fout.close();
    return 0;
}