Cod sursa(job #2806452)

Utilizator realmeabefirhuja petru realmeabefir Data 22 noiembrie 2021 17:48:52
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.16 kb
#include <iostream>
#include <bits/stdc++.h>

#define inf 1000000

using namespace std;

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

int n;
int dist[100][100];
int minDist[100][100];

int main()
{
    in >> n;
    memset(minDist, inf, sizeof(dist));
    memset(dist, inf, sizeof(minDist));

    for (int i = 0; i < n; i++)
        minDist[i][i] = 0;

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            in >> dist[i][j];
            minDist[i][j] = dist[i][j];
        }

    for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                //minDist[i][j] = min(min(minDist[i][j], minDist[i][k] + dist[k][j]), dist[i][k] + minDist[k][j]);
                minDist[i][j] = min(minDist[i][j], minDist[i][k] + minDist[k][j]);

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
            if (minDist[i][j] >= inf)
            {
                out << 0 << ' ';
                continue;
            }
            else
                out << minDist[i][j] << ' ';
        out << '\n';
    }

    return 0;
}