Cod sursa(job #2683377)

Utilizator ddeliaioanaaDumitrescu Delia Ioana ddeliaioanaa Data 11 decembrie 2020 09:01:35
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
#include <bits/stdc++.h>

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

const int INF = 1e9;

int n, ponderi[101][101];
int main()
{
    int i, j, k;
    fin >> n;
    for(i = 0; i < n; i++)
        for(j = 0; j < n; j++){
            fin >> ponderi[i][j];
            if(ponderi[i][j] == 0)
                ponderi[i][j] = INF;
        }

    for(k = 0; k < n; k++)
        for(i = 0; i < n; i++)
            for(j = 0; j < n; j++)
                if( i != j && ponderi[i][k] + ponderi[k][j] < ponderi[i][j])
                    ponderi[i][j] = ponderi[i][k] + ponderi[k][j];

    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            if(ponderi[i][j] != INF)
                fout << ponderi[i][j] << " ";
            else
                fout << 0 << " ";
        }
        fout << '\n';
    }


    return 0;
}