Cod sursa(job #3233641)
| Utilizator | Data | 4 iunie 2024 11:27:55 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int dist[105][105];
int n;
int main() {
in>>n;
for(int i=1;i<=n;++i) {
for(int j=1;j<=n;++j) {
in>>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) {
out<<dist[i][j]<<' ';
}
out<<'\n';
}
return 0;
}