Cod sursa(job #2868305)

Utilizator IonutB56Ionut Birescu IonutB56 Data 10 martie 2022 20:58:31
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int a[257][257],n;
void citire()
{
    f >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            f >> x>> y;
    a[x][y]=1:
        }
}
void afisare()
{
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
            g << a[i][j] << " ";
        g << "\n";
    }
}
void rf()
{
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                if(i!=j && a[i][j] > a[i][k] + a[k][j])
                    a[i][j] = a[i][k] + a[k][j];
}
int main()
{
    citire();
    rf();
    afisare();
}