Pagini recente » Cod sursa (job #1272123) | Cod sursa (job #2986572) | Cod sursa (job #451606) | Cod sursa (job #857693) | Cod sursa (job #2861636)
#include <bits/stdc++.h>
#define oo 2000000001
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int n;
int dist[105][105];
void read() {
f >> n;
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
f >> dist[i][j];
}
}
}
void roy_floyd() {
for (int k=1;k<=n;k++) {
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
if (dist[i][k] && dist[j][k]);
if (dist[i][j]>dist[i][k]+dist[k][j] || (dist[i][j]==0 && i!=j)) {
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
}
void show() {
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
g << dist[i][j] << " ";
}
g << '\n';
}
}
int main()
{
read();
roy_floyd();
show();
return 0;
}