Cod sursa(job #2858690)

Utilizator vladsipunct5555Butnrau Vlad vladsipunct5555 Data 28 februarie 2022 11:15:02
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.76 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in ("royfloyd.in");
ofstream out ("royfloyd.out");
int a[101][101];
void solve()
{
    int n;
    in >> n;
    for (int i = 1;i<=n;++i)
        for (int j = 1;j<=n;++j)
            in >> a[i][j];
    for (int k = 1;k<=n;++k)
        for (int i = 1;i<=n;++i)
            for (int j = 1;j<=n;++j)
                if (a[i][k] && a[k][j] && a[i][k] + a[k][j] < a[i][j])
                    a[i][j] = a[i][k] + a[k][j];
    for (int i = 1;i<=n;++i)
    {
        for (int j = 1;j<=n;++j)
            out << a[i][j] << ' ';
        out << '\n';
    }
}
main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}