Cod sursa(job #1047736)

Utilizator caliuxSegarceanu Calin caliux Data 4 decembrie 2013 20:44:23
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");

int N, i, j, x, y, z, d[105][105];

int minimum(int a, int b){
    if(a < b){
        return a;
    }
    return b;
}

int main(){
    in >> N;
    for(i = 1; i <= N; i++){
        for(j = 1; j <= N; j++){
            in >> d[i][j];
        }
    }
    for(z = 1; z <= N; z++){
        for(x = 1; x <= N; x++){
            for(y = 1; y <= N; y++){
                if(d[x][z] && d[z][y]){
                    d[x][y] = minimum(d[x][z] + d[z][y], d[x][y]);
                }
            }
        }
    }
    for(i = 1; i <= N; i++){
        for(j = 1; j <= N; j++){
            out << d[i][j] << " ";
        }
        out << "\n";
    }
}