Pagini recente » Cod sursa (job #286702) | Cod sursa (job #986170) | Cod sursa (job #2506482) | Cod sursa (job #1677178) | Cod sursa (job #3300826)
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <fstream>
#include <cstring>
#include <vector>
using namespace std;
#define fast_io ios::sync_with_stdio(0); cin.tie(0); do{}while(0)
typedef long long ll;
const int MAXN = 105;
const int INF = 0x3f3f3f3f;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
int graph[MAXN][MAXN];
void ReadData() {
fin >> n;
int a;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
fin >> a;
graph[i][j] = a;
if (a == 0 && i != j) {
graph[i][j] = INF;
}
}
}
}
void RoyFloyd() {
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (graph[i][j] <= graph[i][k] + graph[k][j] || !graph[i][k] || !graph[k][j]) {
continue;
}
graph[i][j] = graph[i][k] + graph[k][j];
}
}
}
}
void Solve() {
RoyFloyd();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
fout << graph[i][j] << ' ';
}
fout << '\n';
}
}
int main() {
ReadData();
Solve();
return 0;
}