Cod sursa(job #1130775)

Utilizator EhtRalpmetFMI Ardei Claudiu-Alexandru EhtRalpmet Data 28 februarie 2014 15:32:43
Problema Floyd-Warshall/Roy-Floyd Scor 90
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
//#include <iostream>
#include<fstream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
ifstream cin("royfloyd.in");
ofstream cout("royfloyd.out");
#define maxn 101

int a,b,m,n,v[maxn][maxn],i,j,k;

int main()
{
    cin>>n;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            cin>>v[i][j];
        }
    }
    for(k=1;k<=n;k++){
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                if(i==j){
                    continue;
                }
                if(v[i][j]==0){
                    v[i][j]=v[i][k]+v[k][j];
                }else{
                    v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
                }
            }
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            cout<<v[i][j]<<' ';
        }
        cout<<'\n';
    }
    return 0;
}