Cod sursa(job #2009109)

Utilizator MihaelaCismaruMihaela Cismaru MihaelaCismaru Data 8 august 2017 16:43:59
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include<fstream>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
int n,f,sol,mat[101][101],cost,i,j,k,minim,a,b;
int main(){
    in >> n ;
    for( i = 1; i <= n; i ++ ){
        for( j = 1; j <= n; j ++ ){
            in >> mat[i][j];
        }
    }
    for( i = 1; i <= n; i ++ ){
        for( j = 1; j <= n; j ++ ){
            if( mat[i][j] == 0 ){
                mat[i][j] = 1e7;
            }
        }
    }


    for( k = 1; k <= n; k ++ ){
        for( i = 1; i <= n; i ++ ){
            if( i != k ){
                for( j = 1; j <= n; j ++ ){
                    if( i != j and mat[i][j] > mat[i][k] + mat[k][j] ){
                        mat[i][j] = mat[i][k] + mat[k][j];
                    }
                }
            }
        }
    }
    for( i = 1; i <= n; i ++ ){
        for( j = 1; j <= n; j ++ ){
            if( mat[i][j] == 1e7 ){
                out<<0<<" ";
            }
            else{
                out<<mat[i][j]<<" ";
            }
        }
        out<<"\n";
    }

    return 0;
}