Cod sursa(job #2686095)

Utilizator speedypleathGheorghe Andrei speedypleath Data 18 decembrie 2020 15:16:48
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
const int INF = 1000000;
int dist[105][105],n;
int main()
{
    in>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            in>>dist[i][j];
            if(dist[i][j] == 0 && i!=j)
                dist[i][j] = INF;
        }


    for(int k=0;k<n;k++)
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(dist[i][k]+dist[k][j]<dist[i][j])
                        dist[i][j] = dist[i][k] + dist[k][j];


    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            if(dist[i][j]==INF)
                out<<"0 ";
            else
                out<<dist[i][j]<<' ';
        out<<'\n';
    }
    return 0;
}