Cod sursa(job #1852745)

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

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

long long nr, i, j, matrice[205][205], 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] = 100000000000;
        }
    }

    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] == 100000000000)
        cout << "0 ";
        else
        cout << matrice[i][j] << ' ';
        cout << '\n';
    }
}