Cod sursa(job #3270792)

Utilizator BuzdiBuzdugan Rares Andrei Buzdi Data 24 ianuarie 2025 15:05:05
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.13 kb
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define ll long long
#define ld long double

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

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

const int NMAX = 100;
const int INF = 2e9;

int n;
int g[NMAX + 1][NMAX + 1];
int d[NMAX + 1][NMAX + 1];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    fin >> n;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            fin >> d[i][j];
        }
    }

    for(int k = 1; k <= n; k++) {
        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                if(i != j && d[i][k] && d[k][j]) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
    }

    for(int i = 1; i <= n; i++, fout << '\n') {
        for(int j = 1; j <= n; j++) {
            fout << d[i][j] << ' ';
        }
    }

    return 0;
}