Cod sursa(job #3255543)

Utilizator andiRTanasescu Andrei-Rares andiR Data 10 noiembrie 2024 23:43:39
Problema Floyd-Warshall/Roy-Floyd Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.13 kb
// Author: Tanasescu Andrei-Rares
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <iomanip>
#include <vector>
#include <cassert>

#pragma GCC optimize("O3")

#define fi first
#define se second
#define pb push_back
#define pf push_front

using namespace std;

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll Nmax=1e2+5, inf=1e9+5;

int n;
int mat[Nmax][Nmax];

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

    fin>>n;
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
            fin>>mat[i][j];

    for (int k=0; k<n; k++)
        for (int i=0; i<n; i++)
            for (int j=1; j<n; j++){
                int d=mat[i][k]+mat[k][j];
                if (d<mat[i][j])
                mat[i][j]=d;
            }

    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++)
            fout<<mat[i][j]<<' ';
        fout<<'\n';
    }

    return 0;
}