Cod sursa(job #3198029)

Utilizator alex210046Bratu Alexandru alex210046 Data 28 ianuarie 2024 10:09:38
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
const int INF = 1e9;
int n, dist[101][101];

int main() {
   f >> n;
   for(int i = 1; i <= n; i++)
      for(int j = 1; j <= n; j++) {
         int x; f >> x;
         dist[i][j] = (x == 0 && i != j) ? INF : x;
      }
   for(int k = 1; k <= n; k++)
      for(int i = 1; i <= n; i++)
         for(int j = 1; j  <= n; j++)
            if(dist[i][j] > dist[i][k] + dist[k][j])
               dist[i][j] = dist[i][k] + dist[k][j];
   for(int i = 1; i <= n; i++) {
      for(int j = 1; j <= n; j++)
         g << ((dist[i][j] != INF) ? dist[i][j] : 0) << ' ';
      g << '\n';
   }

   return 0;
}