Cod sursa(job #3337075)
| Utilizator | Data | 26 ianuarie 2026 21:52:27 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
//roy floyd
#include <bits/stdc++.h>
using namespace std;
int dist[101][101];
int main() {
int n;
cin>>n;
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++) {
cin>>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][k]!=0 && dist[k][j]!=0 && (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++) {
cout<<dist[i][j]<<' ';
}
cout<<'\n';
}
}