Cod sursa(job #3257803)

Utilizator alexboat10759Alex Mateescu alexboat10759 Data 19 noiembrie 2024 15:45:06
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-32 Status done
Runda Arhiva educationala Marime 1.14 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 <bits/stdc++.h>
#define int long long
int mat[105][105];
using namespace std;
signed main()
{
    ifstream cin("royfloyd.in");
    ofstream cout("royfloyd.out");
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>mat[i][j];
        }
    }
    for(int k=0;k<n;k++)
    {
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(mat[i][j]&&mat[i][k]&&mat[j][k])
                {
                    mat[i][j]=min(mat[i][j],mat[i][k]+mat[k][j]);
                }
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cout<<mat[i][j]<<" ";
        }
        cout<<'\n';
    }
    return 0;
}