Cod sursa(job #2361964)

Utilizator PaulRPFRebenciuc Paul-Florin PaulRPF Data 2 martie 2019 20:50:53
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int Cost[102][102],i,j,k,N;

void RF()
{
    for(k=1;k<=N;k++)
    for(i=1;i<=N;i++)
    for(j=1;j<=N;j++)
    if(k!=i and k!=j and i!=j and Cost[i][k]+Cost[k][j]<Cost[i][j])
        Cost[i][j]=Cost[i][k]+Cost[k][j];
}
int main()
{
    f>>N;
    for(i=1;i<=N;i++)
    for(j=1;j<=N;j++)
    {
        f>>Cost[i][j];
        if(Cost[i][j]==0)Cost[i][j]=INF;
    }

    RF();
    for(i=1;i<=N;i++)
    {
        for(j=1;j<=N;j++)
        if(Cost[i][j]==INF)g<<"0 ";
        else g<<Cost[i][j]<<" ";
        g<<"\n";
    }
    return 0;
}