Mai intai trebuie sa te autentifici.
Cod sursa(job #2355608)
| Utilizator | Data | 26 februarie 2019 10:39:19 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.66 kb |
#include <bits/stdc++.h>
using namespace std;
int d[105][105];
int main() {
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
int n;
cin >> n;
for(int i = 1;i <= n;i++)
for(int j = 1;j <= n;j++)
cin >> d[i][j];
for(int k = 1;k <= n;k++)
for(int i = 1;i <= n;i++)
for(int j = 1;j <= n;j++) {
if(k != i && k != j)
d[i][j] = min(d[i][k] + d[k][j], d[i][j]);
}
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++) {
cout << d[i][j] << " ";
}
cout << "\n";
}
return 0;
}
