Cod sursa(job #2844693)

Utilizator cristi_macoveiMacovei Cristian cristi_macovei Data 5 februarie 2022 10:15:49
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.07 kb
#define d(x) std::cout << x << std::endl
#define dm(msg, x) std::cout << msg << x << std::endl

#define all(a) a.begin(), a.end()
#define range(a, l, r) a.begin() + l, a.begin() + r
#define aall(a, n) a + 1, a + 1 + n
#define arange(a, l, r) a + l, a + r
	
#define maxself(a, b) a = std::max(a, b);
#define minself(a, b) a = std::min(a, b);

#define inout(f) std::ifstream in((f) + (std::string) ".in");std::ofstream out((f) + (std::string) ".out")

#include <iostream>
#include <fstream>

const int NMAX = 100;

int dist[1 + NMAX][1 + NMAX];

int main() {
  inout("royfloyd");
  
  int n;
  in >> n;

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

  for (int k = 1; k <= n; ++k) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        if (i != k && j != k && i != j)
          minself(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j)
      out << dist[i][j] << ' ';
    out << '\n';
  }

  return 0;
}