Cod sursa(job #2802564)

Utilizator Luca_Miscocilucainfoarena Luca_Miscoci Data 18 noiembrie 2021 13:08:23
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>
#include <queue>
#define INF 100000
#define NMAX 100

using namespace std;

int nod[NMAX + 1][NMAX + 1];

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

  int n;
  fin >> n;

  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++){
      fin >> nod[i][j];
      if (nod[i][j] == 0 && i != j)
        nod[i][j] = INF;
    }
  }

  for (int l = 0; l < n; l++){
    for (int i = 0; i < n; i++){
      for (int j = 0; j < n; j++)
        if (nod[i][l] + nod[l][j] < nod[i][j])
          nod[i][j] = nod[i][l] + nod[l][j];
    }
  }

  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++)
      fout << nod[i][j] << " ";
    fout << "\n";
  }
  return 0;
}