Pagini recente » Cod sursa (job #1717987) | Cod sursa (job #2757227) | Cod sursa (job #2306239) | Cod sursa (job #2334922) | Cod sursa (job #1967313)
#include <iostream>
#include <fstream>
#include <queue>
#include <vector>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
typedef long long ll;
const int NMax = 105;
const int inf = 1e9 + 5;
int N;
int dist[NMax][NMax][NMax];
int main() {
in>>N;
for (int i=1;i<=N;++i) {
for (int j=1;j<=N;++j) {
in>>dist[i][j][0];
if (!dist[i][j][0] && i!=j) {
dist[i][j][0] = inf;
}
}
}
for (int k=1;k<=N;++k) {
for (int i=1;i<=N;++i) {
for (int j=1;j<=N;++j) {
dist[i][j][k] = min(dist[i][j][k-1],dist[i][k][k-1] + dist[k][j][k-1]);
}
}
}
for (int i=1;i<=N;++i) {
for (int j=1;j<=N;++j) {
out<<((dist[i][j][N] == inf) ? 0 : dist[i][j][N])<<' ';
}
out<<'\n';
}
in.close();out.close();
return 0;
}