Mai intai trebuie sa te autentifici.
Cod sursa(job #2419626)
| Utilizator | Data | 8 mai 2019 23:07:50 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.97 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
#define inf 100005
#define NMAX 105
int n, dist[NMAX][NMAX];
// j, i+1
void citire(){
f>>n;
for(int i = 1 ; i <= n; i ++)
for(int j = 1; j <= n; j ++)
f>>dist[i][j];
}
void RoyFloyd(){
for(int i = 1 ; i <= n; i ++)
dist[i][i] = 0;
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[k][j] < dist[i][j])
dist[i][j] = dist[i][k] + dist[k][j];
}
void afisare(){
for(int i = 1 ; i <= n; i ++)
{
for(int j = 1; j <= n; j ++)
if(dist[i][j] == inf)
g<<0<<" ";
else
g<<dist[i][j]<< " ";
g<<endl;
}
}
int main()
{
citire();
RoyFloyd();
afisare();
return 0;
}
