Pagini recente » Cod sursa (job #2287451) | Cod sursa (job #2583934) | Cod sursa (job #1952557) | Cod sursa (job #565670) | Cod sursa (job #1881587)
#include <bits/stdc++.h>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
const int NMax = 103;
int n;
int a[NMax][NMax];
int main()
{
f >> n;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
f >> a[i][j];
for(int inter = 1; inter <= n; ++inter){
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
if(i != j){
if(a[i][j] != 0 && a[i][j] > a[i][inter] + a[inter][j]){
a[i][j] = a[i][inter] + a[inter][j];
}
}
}
}
}
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= n; ++j){
g << a[i][j] << ' ';
}
g << '\n';
}
return 0;
}