Cod sursa(job #3360231)
| Utilizator | Data | 10 iulie 2026 18:57:55 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
const int nmax = 100;
int dist[nmax][nmax];
int main() {
int n; f >> n;
for(int i = 0, j; i < n; i ++)
for(j = 0; j < n; j ++)
f >> dist[i][j];
for(int i, j, k = 0; k < n; k ++)
for(i = 0; i < n; i ++)
for(j = 0; j < n; j ++)
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
for(int i = 0, j; i < n; i ++)
for(j = 0; j < n; j ++)
g << dist[i][j] << " \n"[j == n - 1];
}