Pagini recente » Cod sursa (job #23477) | Cod sursa (job #939733) | Cod sursa (job #3152257) | Cod sursa (job #762991) | Cod sursa (job #1726241)
#include <iostream>
#include <stdio.h>
#define N 105
using namespace std;
int n;
int cost[N][N];
void read()
{
freopen("royfloyd.in","r",stdin);
freopen("royfloyd.out","w",stdout);
scanf("%d\n",&n);
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < n ; j++)
{
scanf("%d ",&cost[i][j]);
if(cost[i][j] == 0)
cost[i][j] = 1010;
}
}
void drum_minim()
{
for(int k = 0 ; k < n ; k++)
{
for(int i = 0 ; i < n ; i++)
{
if(i != k)
{
for(int j = 0 ; j < n ; j++)
{
if(j != k)
{
if(cost[i][j] > cost[k][j] + cost[i][k])
cost[i][j] = cost[k][j] + cost[i][k];
}
}
}
}
}
}
void afisare()
{
for(int i = 0 ; i <n ; i++)
{
for(int j = 0 ; j < n ; j++)
{
if(i == j)
{printf("%d ", 0);
continue;}
if(cost[i][j] == 1010)
{printf("%d ", 0);
continue;}
printf("%d ",cost[i][j]);
}
printf("\n");
}
}
int main()
{
read();
drum_minim();
afisare();
return 0;
}