Cod sursa(job #2868301)

Utilizator IonutB56Ionut Birescu IonutB56 Data 10 martie 2022 20:54:52
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.78 kb
#include <iostream>
#include <fstream>

#include <iostream>
#include <fstream>
using namespace std;
ifstream f("rf.in");
ofstream g("rf.out");
int a[257][257],b[257][257],n, m, c, i, j,x,y,k;
void citire()
{
    f >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            f >> a[i][j];
}
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();
}