Pagini recente » Cod sursa (job #2539508) | Cod sursa (job #1400505) | Cod sursa (job #522516) | Cod sursa (job #604323) | Cod sursa (job #3192626)
#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const char sp = ' ';
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const char out[2][4]{ "NO", "YES" };
#define all(a) a.begin(), a.end()
using ll = long long;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int nmax = 100;
int n;
ll d[nmax + 5][nmax + 5]{ 0 };
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
fin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
int w;
fin >> w;
if (i == j) {
continue;
}
d[i][j] = w ? w : inf;
}
}
for (int k = 1; k <= n; ++k) {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
fout << d[i][j] << sp;
}
fout << nl;
}
}