Cod sursa(job #1992018)

Utilizator vpielePiele Valentin Gabriel vpiele Data 19 iunie 2017 02:48:34
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <fstream>
#define Vmax 100
using namespace std;

int main()
{
    ifstream input("royfloyd.in");
    ofstream output("royfloyd.out");

    int V;
    input >> V;

    int i, j, k;
    int dist[Vmax][Vmax];
    for(i = 0; i < V; i ++)
        for(j = 0; j < V; j ++)
            dist[i][j] = 1 << 16;
    output << dist[2][2] << '\n';
    for(i = 0; i < V; i ++)
        for(j = 0; j < V; j ++)
            input >> dist[i][j];

    for(k = 0; k < V; k ++)
        for(i = 0; i < V; i ++)
            for(j = 0; j < V; j ++)
                if(dist[i][j] > dist[i][k] + dist[k][j])
                    dist[i][j] = dist[i][k] + dist[k][j];
    for(i = 0; i < V; i ++)
    {
        for(j = 0; j < V; j ++)
            output << dist[i][j] << ' ';
        output << '\n';
    }
    return 0;
}