Cod sursa(job #3192878)

Utilizator CastielGurita Adrian Castiel Data 13 ianuarie 2024 13:43:02
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.38 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n,mat[105][105],matp[105][105];
int main()
{
    fin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            fin>>mat[i][j];
            if(mat[i][j]==0)
            {
                mat[i][j]=1e9;
            }
        }
    }
    for(int k = 1 ; k <= n ; k ++)
    {
        for(int i = 1 ; i <= n ; i ++)
        {
            for(int j = 1 ; j <= n ; j ++)
            {
                if(i==j)
                {
                    continue;
                }
                if(mat[i][j] > mat[i][k] + mat[k][j])
                {
                    mat[i][j] = mat[i][k] + mat[k][j];
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            fout<<mat[i][j]<<" ";
        }
        fout<<'\n';
    }
    fin.close();
    fout.close();
    return 0;
}