Pagini recente » Cod sursa (job #1425693) | Cod sursa (job #3218482) | Cod sursa (job #358621) | Cod sursa (job #348928) | Cod sursa (job #3296223)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
const int MAXN = 100;
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];
}
}
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++) {
fout << dist[i][j] << " ";
}
fout << "\n";
}
return 0;
}