Pagini recente » Cod sursa (job #2036533) | Cod sursa (job #2169203) | Cod sursa (job #1522775) | Cod sursa (job #1425831) | Cod sursa (job #2661258)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream f("in.in");
ofstream g("out.out");
int N, Cost[100][100];
f >> N;
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
{
f >> Cost[i][j];
if(Cost[i][j] == 0 && i != j)
Cost[i][j] = 1001;
}
for(int k = 0; k < N; k++)
for(int i = 0; i < N; i++)
for(int j = 0; j < N; j++)
if(Cost[i][k] + Cost[k][j] < Cost[i][j])
Cost[i][j] = Cost[i][k] + Cost[k][j];
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
if(Cost[i][j] == 1001 && i != j)
g << 0 << ' ';
else
g << Cost[i][j] << ' ';
g << '\n';
}
return 0;
}