Cod sursa(job #3030255)

Utilizator T1raduTaerel Radu Nicolae T1radu Data 17 martie 2023 16:16:25
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n,A[101][101];
int main()
{
    fin >> n;
    for(int i=1; i<=n; i++)
    {
        for(int j=1;j<=n;j++)
            fin >> A[i][j];
    }
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(A[i][k]!=0 && A[k][j]!=0)
                {
                    if(A[i][j]!=0) A[i][j]=min(A[i][j],A[i][k]+A[k][j]);
                    else A[i][j]=A[i][k]+A[k][j];
                }
            }
        }
    }
    for(int i=1; i<=n; i++)
    {
        for(int j=1;j<=n;j++)
            fout << A[i][j] << " ";
        fout << "\n";
    }
    return 0;
}