Cod sursa(job #1876823)
Utilizator | Bejan Irina Flowstatic | Data | 12 februarie 2017 17:47:34 |
---|---|---|---|
Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.6 kb |
#include <fstream>
#define NMAX 105
#define FOR(i,a,b) for(int i = a; i <= b; i++)
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int mat[NMAX][NMAX];
int N;
int main()
{
fin>>N;
FOR(i,1,N)
FOR(j,1,N)
{
fin>>mat[i][j];
}
FOR(k,1,N)
FOR(i,1,N)
FOR(j,1,N)
{
if(mat[i][k]+mat[k][j] < mat[i][j])
mat[i][j] = mat[i][k]+mat[k][j];
}
FOR(i,1,N)
{
FOR(j,1,N)
fout<<mat[i][j]<<" ";
fout<<'\n';
}
return 0;
}