Pagini recente » Cod sursa (job #1993259) | Cod sursa (job #571584) | Cod sursa (job #977948) | Cod sursa (job #2246117) | Cod sursa (job #1360080)
#include<cstdio>
#include<string>
using namespace std;
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "royfloyd";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif
const int INF = (1 << 30) - 1;
const int NMAX = 100 + 5;
int N;
int A[NMAX][NMAX];
int main() {
int i, j, k;
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
scanf("%d", &N);
for(i = 1; i <= N; i++)
for(j = 1; j <= N; j++)
scanf("%d", &A[i][j]);
for(k = 1; k <= N; k++)
for(i = 1; i <= N; i++)
for(j = 1; j <= N; j++)
if(A[i][k] && A[k][j] && i != j && i != k && j != k)
A[i][j] = min(A[i][j] ? A[i][j] : INF, A[i][k] + A[k][j]);
for(i = 1; i <= N; i++) {
for(j = 1; j <= N; j++)
printf("%d ", A[i][j]);
printf("\n");
}
return 0;
}