Pagini recente » Cod sursa (job #1137182) | Cod sursa (job #1092860) | Cod sursa (job #2648810) | Cod sursa (job #43419) | Cod sursa (job #2537186)
#include <bits/stdc++.h>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
const int oo = (int) (1e9);
const int dim = 101;
int n, w[dim][dim], a[dim][dim];
int main()
{
in>>n;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
{
in>>w[i][j];
if(i != j)
if(w[i][j] != 0)
a[i][j] = w[i][j];
else
a[i][j] = oo;
}
for(int k = 1; k <= n; k++)
{
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; 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++)
out<<a[i][j]<<' ';
out<<'\n';
}
return 0;
}