Cod sursa(job #2686091)

Utilizator speedypleathGheorghe Andrei speedypleath Data 18 decembrie 2020 15:13:18
Problema Floyd-Warshall/Roy-Floyd Scor 50
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++)
            dist[i][j] = i==j ? 0 : INF;

    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            in>>dist[i][j];

    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;
}