Cod sursa(job #2423623)
Utilizator | Data | 21 mai 2019 19:23:37 | |
---|---|---|---|
Problema | Floyd-Warshall/Roy-Floyd | Scor | 40 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.55 kb |
#include <fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int n, c[100][100];
int main ()
{
f>>n;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
f>>c[i][j];
for(int k=1; k<=n; k++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
if( c[i][k] + c[k][j] < c[i][j])
c[i][j] = c[i][k] + c[k][j];
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
g<<c[i][j]<<" ";
g<<endl;
}
}