Cod sursa(job #3213929)

Utilizator AndreiBOTOBotocan Andrei AndreiBOTO Data 13 martie 2024 16:57:25
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.06 kb
#include <bits/stdc++.h>

#pragma optimize GCC ("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

///#include <tryhardmode>
///#include <GODMODE::ON>

using namespace std;

ifstream fin ("royfloyd.in");
ofstream fout ("royfloyd.out");

#define cin fin
#define cout fout

const int NMAX=1e2+5;

int a[NMAX][NMAX];
int dist[NMAX][NMAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n,i,j,k;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
            cin>>a[i][j];
    }
    for(k=1;k<=n;k++)
    {
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=n;j++)
            {
                if(i!=j && dist[i][k] && dist[k][j] && (dist[i][j]==0 || dist[i][j]>dist[i][k]+dist[k][j]))
                    dist[i][j]=dist[i][k]+dist[k][j];
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
            cout<<dist[i][j]<<" ";
        cout<<"\n";
    }
    cin.close();
    cout.close();
    return 0;
}