Cod sursa(job #1856120)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 24 ianuarie 2017 15:44:40
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <bits/stdc++.h>
using namespace std;

constexpr int maxn = 110;

int main(){
    ifstream f("royfloyd.in");
    ofstream g("royfloyd.out");
    int n, d[maxn][maxn];
    f >> n;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            f >> d[i][j]; } }
    for(int k = 0; k < n; ++k){
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                if(i != j && j != k && i != k && d[i][k] && d[k][j] &&
                    (d[i][j] == 0 || d[i][j] > d[i][k] + d[k][j])){
                    d[i][j] = d[i][k] + d[k][j]; } } } }
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            g << d[i][j] << ' '; }
        g << '\n'; }
    return 0; }