Cod sursa(job #2758495)

Utilizator rARES_4Popa Rares rARES_4 Data 10 iunie 2021 18:06:16
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 kb
#include <iostream>
#include <fstream>
#include <climits>
using namespace std;
ifstream f ("royfloyd.in");
ofstream g ("royfloyd.out");
int n;
int costuri[101][101],vecini[101][101];
int main()
{
    f >> n;
    for(int i = 1; i<=n; i++)
    {
        for(int j = 1; j<=n; j++)
        {
            f >> costuri[i][j];
            if(!costuri[i][j])
                costuri[i][j] = 1001;
        }
    }

    for(int k = 1; k<=n; k++)
    {
        for(int i = 1; i<=n; i++)
        {
            for(int j = 1; j<=n; j++)
            {
                if(i!=k && j != k  && i !=j && costuri[i][j]>costuri[i][k] + costuri[k][j])
                    costuri[i][j] = costuri[i][k] + costuri[k][j];
            }
        }
    }

    for(int i = 1; i<=n; i++)
    {
        for(int j = 1; j<=n; j++)
        {
            if(costuri[i][j]!=1001)
                g << costuri[i][j]<< " ";
            else
                g << "0 ";
        }
        g << endl;
    }
}