Cod sursa(job #1852728)

Utilizator vlad6001Pintilie Vlad vlad6001 Data 21 ianuarie 2017 10:00:07
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <fstream>
#define INF 1000000
using namespace std;

ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");

int nr, i, j, matrice[1005][1005], k, x, y;

int main()
{
    cin >> nr;
    for(i=1; i <= nr; i++)
    {
        for(j=1; j <= nr; j++)
        {
            cin >> matrice[i][j];
            if(matrice[i][j] == 0)
            matrice[i][j] = INF;
        }
    }

    for(k=1; k <= nr; k++)
    {
        for(x=1; x <= nr; x++)
        {
            for(y=1; y <= nr; y++)
            {
                if(matrice[x][y] > matrice[x][k] + matrice[k][y])
                {
                    matrice[x][y] = matrice[x][k] + matrice[k][y];
                    //ft[x][y] = k;
                }
            }
        }
    }
    for(i=1; i <= nr; i++)
    {
        for(j=1; j <= nr; j++)
        if(i == j || matrice[i][j] == INF)
        cout << "0 ";
        else
        cout << matrice[i][j] << ' ';
        cout << '\n';
    }
}