Cod sursa(job #3183560)

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

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

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];

    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 d[i][k] == 0 or d[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 )
            out << dist[i][j] << " ";

    return 0;
}