Cod sursa(job #3130809)

Utilizator AndreiN96Andrei Nicula AndreiN96 Data 18 mai 2023 17:46:04
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>

using namespace std;

const int N = 100, INF = 1001;
int cost[N + 1][N + 1];

int main()
{
    ifstream in("royfloyd.in");
    ofstream out("royfloyd.out");

    int n;
    in >> n;
    for (int i = 1; i <= n; i ++)
    {
        for (int j = 1; j <= n; j ++)
        {
            cost[i][j] = INF;
        }
    }
    for (int i = 1; i <= n; i ++)
    {
        for (int j = 1; j <= n; j ++)
        {
            in >> cost[i][j];
        }
    }

    for (int k = 1; k <= n; k ++)
    {
        for (int i = 1; i <= n; i ++)
        {
            for (int j = 1; j <= n; j ++)
            {
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }

    for (int i = 1; i <= n; i ++)
    {
        for (int j = 1; j <= n; j ++)
        {
            out << cost[i][j] << ' ';
        }
        out << '\n';
    }

    in.close();
    out.close();

    return 0;
}