Pagini recente » Cod sursa (job #895448) | Cod sursa (job #836736) | Cod sursa (job #1805362) | Cod sursa (job #542025) | Cod sursa (job #1977590)
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
#define pb push_back
#define ll long long
const int NMax = 1e2 + 5;
const int inf = 1e9 + 5;
int N;
int dist[NMax][NMax];
int main()
{
in>>N;
for (int i=1;i <= N;++i) {
for (int j=1;j <= N;++j) {
in>>dist[i][j];
dist[i][j] = (i != j && dist[i][j] == 0) ? inf : dist[i][j];
}
}
for (int k=1;k <= N;++k) {
for (int i=1;i<=N;++i) {
for (int j=1;j<=N;++j) {
if (dist[i][j] > dist[i][k] + dist[k][j]) {
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
for (int i=1;i <= N;++i) {
for (int j=1;j <= N;++j) {
out<<dist[i][j]<<' ';
}
out<<'\n';
}
in.close();out.close();
return 0;
}