Cod sursa(job #1104639)

Utilizator muresan_bogdanMuresan Bogdan muresan_bogdan Data 10 februarie 2014 21:53:07
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include<iostream>
#include<fstream>
using namespace std;

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

const int INF = 99999999;

int n, i, aux, j, k, dist[101][101];

int main() {
    fin >> n;
    for(i = 0; i < n; i++) {
        for(j = 0; j < n; j++) {
            fin >> aux;
            if((aux == 0) && (i != j)) {
                dist[i][j] = INF;
            }
            else {
                dist[i][j] = aux;
            }
        }
    }
    for(k = 0; k < n; k++) {
        for(i = 0; i < n; i++) {
            for(j = 0; j < n; j++) {
                if(dist[i][j] > dist[i][k] + dist[k][j]) {
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
            }
        }
    }
    for(i = 0; i < n; i++) {
        for(j = 0; j < n; j++) {
                fout << dist[i][j] << ' ';
        }
        fout << '\n';
    }
    fin.close();
    fout.close();
    return 0;
}