Pagini recente » Cod sursa (job #1793405) | Cod sursa (job #143865) | Cod sursa (job #1243696) | Cod sursa (job #3220504) | Cod sursa (job #3296229)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int MAXN = 100;
const int INFINIT = 1000000001;
int dist[MAXN + 1][MAXN + 1];
int main() {
int n;
fin >> n;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
fin >> dist[i][j];
if(dist[i][j] == 0) {
dist[i][j] = INFINIT;
}
}
}
for(int k = 1; k <= n; k++) {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
if(dist[i][j] == INFINIT || i == j) {
dist[i][j] = 0;
}
fout << dist[i][j] << " ";
}
fout << "\n";
}
return 0;
}