Pagini recente » Cod sursa (job #1522217) | Cod sursa (job #2367552) | Cod sursa (job #1738580) | Cod sursa (job #2990410) | Cod sursa (job #2913629)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd");
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';
}
}