Cod sursa(job #3192869)

Utilizator CastielGurita Adrian Castiel Data 13 ianuarie 2024 13:29:51
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.19 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];
        }
    }
    for(int k = 1 ; k <= n ; k ++)
    {
        for(int i = 1 ; i <= n ; i ++)
        {
            for(int j = 1 ; j <= n ; j ++)
            {
                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;
}