Cod sursa(job #1665313)

Utilizator cordun_cristinaCristina Maria Cordun cordun_cristina Data 26 martie 2016 20:15:52
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");

const int Nmax = 105, oo = 10000000;
int n, G[Nmax][Nmax];

int main()
{
    f>>n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        {
            f>>G[i][j];
            if(G[i][j] == 0 && i != j) G[i][j] = oo;
        }
    for(int k = 1; k <= n; k++)
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
            }
        }
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(G[i][j] == oo) g<<0<<' ';
            else g<<G[i][j]<<' ';
        }
        g<<'\n';
    }
    return 0;
}