Cod sursa(job #3183567)

Utilizator SorinBossuMarian Sorin SorinBossu Data 12 decembrie 2023 11:48:32
Problema Floyd-Warshall/Roy-Floyd Scor 20
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.01 kb
#include <iostream>
#include <vector>
#include <fstream>

std::ifstream in("royfloyd.in");
std::ofstream out("royfloyd.out");

constexpr int nmax= 1001;
const int OO = 1e9;
std::vector<std::pair<int, int>> adj[nmax];

int dist[nmax][nmax];
int n,m;

int main()
{
    in >> n;
    for ( int i = 1; i <= n; ++i )
        for ( int j = 1; j <= n; ++j ){
            in >> dist[i][j];
            if ( dist[i][j] == 0 )
                dist[i][j] = OO;
        }

    for ( int i = 1; i <= n; ++i )
        for ( int j = 1; j <= n; ++j )
           for ( int k = 1; k <= n; ++k )
             if ( i == j or i == k or j == k or dist[i][k] == 0 or dist[k][j] == 0)
               continue;
           else
              dist[i][j] = std::min( dist[i][j], dist[i][k]+ dist[k][j]);
    for ( int i = 1; i <= n; ++i, out << "\n")
        for ( int j = 1; j <= n; ++j )
            if ( dist[i][j] == OO )
              out << 0 << " ";
        else
            out << dist[i][j] << " ";

    return 0;
}