Cod sursa(job #2136186)

Utilizator ade_tomiEnache Adelina ade_tomi Data 19 februarie 2018 18:45:21
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <fstream>
#include <iostream>

using namespace std;

const int NMAX = 101;

int d[NMAX][NMAX];

int main() {
  int n, m;

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

  cin >> n;

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

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << d[i][j] << " ";
    }
    cout << '\n';
  }

  return 0;
}