Cod sursa(job #3197867)

Utilizator AlbertPavPavalache Albert AlbertPav Data 27 ianuarie 2024 16:29:32
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <iostream>
#include <fstream>
using namespace std;
const int INF = 1000000;

int n, C[101][101];

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

int main()
{
    int cost;
    f >> n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
            f >> C[i][j];
    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
            {
                cost = C[i][k] + C[k][j];
                if(cost < C[i][j])
                    C[i][j] = cost;
            }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
            g << C[i][j] << ' ';
        g << '\n';
    }
    return 0;
}