Pagini recente » Cod sursa (job #1441616) | Cod sursa (job #1985482) | Cod sursa (job #28237) | Cod sursa (job #2856873) | Cod sursa (job #2861632)
#include <bits/stdc++.h>
#define oo 2000000001
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int n;
int dist[105][105];
int muchii[105][105];
void read() {
f >> n;
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
f >> muchii[i][j];
dist[i][j] = muchii[i][j];
}
}
}
void roy_floyd() {
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
for (int k=1;k<=n;k++) {
dist[i][j] = min(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;
}