Cod sursa(job #2964900)

Utilizator Emmy432622Rotariu Emanuel Emmy432622 Data 14 ianuarie 2023 09:31:15
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin ("royfloyd.in");
ofstream fout("royfloyd.out");

const int Mx = 1000000000;
int d[105][105];
int n;

int main()
{

    fin >> n;

    for(int i = 1 ; i <= n ; ++i)
        for(int j = 1 ; j <= n ; ++j)
        {
            fin >> d[i][j];
        }

    for(int z = 1 ; z <= n ; ++z)
        for(int x = 1 ; x <= n ; ++x)
            for(int y = 1 ; y <= n ; ++y)
                if(d[x][y]&&d[x][z]&&d[z][y])
                d[x][y] = min(d[x][y],d[x][z]+d[z][y]);

    for(int i = 1 ; i <= n ; ++i)
    {
      for(int j = 1 ; j <= n ; ++j)
        {
          if(d[i][j] >= Mx)
            fout << 0;
          else
            fout << d[i][j];
          fout << ' ';
        }
      fout << '\n';
    }

    return 0;
}