Cod sursa(job #3302956)

Utilizator SimifilLavrente Simion Simifil Data 12 iulie 2025 12:56:19
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iostream>
#include <algorithm>
#include <fstream>
#include <cmath>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
#define INF 1e9

int main() {
    ios_base::sync_with_stdio(false);
    f.tie(nullptr);
    g.tie(nullptr);

    int n;
    f >> n;
    int c[n+1][n+1], d[n+1][n+1];
    for( int i = 1; i <= n; i++ )
    {
        for( int j = 1; j <= n; j++ )
        {
            f >> c[i][j];
            d[i][j] = c[i][j];
        }
    }
    for( int k = 1; k <= n; k++ )
    {
        for( int i = 1; i <= n; i++ )
        {
            for( int j = 1; j <= n; j++ )
            {
                d[i][j] = min( d[i][j], d[i][k] + d[k][j] );
            }
        }
    }
    for( int i = 1; i <= n; i++ )
        {
            for( int j = 1; j <= n; j++ )
            {
                    g << d[i][j] << " ";
            }
            g << "\n";
        }

    return 0;
}