Cod sursa(job #1200880)

Utilizator bvanceaBogdan Vancea bvancea Data 23 iunie 2014 19:27:44
Problema Floyd-Warshall/Roy-Floyd Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <fstream>

using namespace std;

void floyd_warshall() {

}

int main(void) {
    ifstream in("royfloyd.in");
    ofstream out("royfloyd.out");
    int t;
    in >> t;
    int w[100][100];    
    for (int i = 0; i < t; i++) {
        for (int j = 0; j < t; j++) {
            in >> w[i][j]; 
        }
    }

    //run floyd warshall:
    //  for any 2 nodes i and j, if the distance going from i to j through
    //  another node k is smaller than dist(i,j), update dist[i,j]
    for (int i = 0; i < t; i++) {
        for (int j = 0; j < t; j++) {
            for (int k = 0; k < t; k++) {
                if (w[i][j] > w[i][k] + w[k][j]) {
                    w[i][j] = w[i][k] + w[k][j];
                }
            }
        }
    }

    //output distance matrix
    for (int i = 0; i < t; i++) {
        for (int j = 0; j < t; j++) {
            out << w[i][j] << " "; 
        }
        out << "\n";
    }
    return 0;
}