Pagini recente » Cod sursa (job #1393277) | Cod sursa (job #2777097) | Cod sursa (job #312310) | Cod sursa (job #634681) | Cod sursa (job #3192665)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n, cost[101][101];
int main(){
fin >> n;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
fin >> cost[i][j];
}
}
for(int z = 1; z <= n; z++)
for(int x = 1; x <= n; x++)
for(int y = 1; y <= n; y++)
if(cost[x][z] && cost[z][y] && cost[x][z] + cost[z][y] < cost[x][y] && cost[x][y])
cost[x][y] = cost[x][z] + cost[z][y];
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++)
cout << cost[i][j] << ' ';
cout << '\n';
}
}