Cod sursa(job #2171602)

Utilizator HD650Stoicescu Adrian Nicolae HD650 Data 15 martie 2018 12:51:55
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.2 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
const long long INF = 1LL << 60;
long long C[101][101];
int n, m;

void afis()
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
            if(C[i][j] == INF)
                g << "0 ";
            else
                g << C[i][j] << ' ';
        g << '\n';
    }
}

void citire()
{
    int x;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        {
            f >> x;
            if(x == 0 && i != j)
                C[i][j] = INF;
            else
                C[i][j] = x;
        }
}
/*
void init()
{
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
            C[i][j] = INF;
        C[i][i] = 0;
    }
}
*/
void Roy_Floyd()
{
    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
            {
                long long s = C[i][k] + C[k][j];
                if(C[i][j] > s)
                    C[i][j] = s;
            }
}

int main()
{
    f >> n;
    citire();
    Roy_Floyd();
    afis();
    return 0;
}