Mai intai trebuie sa te autentifici.
Cod sursa(job #2861636)
| Utilizator | Data | 4 martie 2022 10:34:40 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 90 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.89 kb |
#include <bits/stdc++.h>
#define oo 2000000001
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int n;
int dist[105][105];
void read() {
f >> n;
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
f >> dist[i][j];
}
}
}
void roy_floyd() {
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] && dist[j][k]);
if (dist[i][j]>dist[i][k]+dist[k][j] || (dist[i][j]==0 && i!=j)) {
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
}
void show() {
for (int i=1;i<=n;i++) {
for (int j=1;j<=n;j++) {
g << dist[i][j] << " ";
}
g << '\n';
}
}
int main()
{
read();
roy_floyd();
show();
return 0;
}
