Cod sursa(job #2537186)

Utilizator sipdavSipos David Oliver sipdav Data 3 februarie 2020 11:42:32
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <bits/stdc++.h>

using namespace std;

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

const int oo = (int) (1e9);
const int dim = 101;

int n, w[dim][dim], a[dim][dim];

int main()
{
    in>>n;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        {
            in>>w[i][j];
            if(i != j)
                if(w[i][j] != 0)
                    a[i][j] = w[i][j];
                else
                    a[i][j] = oo;
        }
    for(int k = 1; k <= n; k++)
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(a[i][j] > a[i][k] + a[k][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';
    }
    return 0;
}