Pagini recente » Cod sursa (job #2711053) | Cod sursa (job #1304574) | Cod sursa (job #963707) | Cod sursa (job #2011139) | Cod sursa (job #1930206)
#include <cstdio>
#include <algorithm>
using namespace std;
const int inf = 0x3fffffff;
int n;
int mat[102][102];
void citire()
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
scanf("%d", &mat[i][j]);
if(mat[i][j] == 0)
{
mat[i][j] = inf;
}
}
}
}
void solve()
{
for(int k = 0; k < n; k++)
{
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(i == j)
{
continue;
}
if(mat[i][j] > mat[i][k] + mat[k][j])
{
mat[i][j] = mat[i][k] + mat[k][j];
}
}
}
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(i == j)
{
printf("0 ");
}
else if(mat[i][j] == inf)
{
printf("0 ");
}
else
{
printf("%d ", mat[i][j]);
}
}
printf("\n");
}
}
int main()
{
freopen("royfloyd.in", "r", stdin);
freopen("royfloyd.out", "w", stdout);
citire();
solve();
return 0;
}