Pagini recente » Cod sursa (job #3123852) | Romanian IOI Medalists: Careers | Cod sursa (job #836557) | Cod sursa (job #1060019) | Cod sursa (job #2913628)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("roy-floyd.in");
ofstream fout("roy-floyd.out");
int n, x, a[101][101];
int main(){
fin >> n;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
fin >> a[i][j];
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
if(i != j && a[i][j] == 0)
a[i][j] = 100001;
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
if(i != j)
if(a[i][j] > a[i][k] + a[k][j])
a[i][j] = a[i][k] + a[k][j];
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(a[i][j] != 100001)
fout << a[i][j] << ' ';
else
fout << 0 << ' ';
}
fout << '\n';
}
}