Cod sursa(job #1047734)

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

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

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++){
                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";
    }
}