Cod sursa(job #2570036)

Utilizator Ioan_AnghelIoan Anghel Ioan_Anghel Data 4 martie 2020 14:47:29
Problema Floyd-Warshall/Roy-Floyd Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const int N = 103, INF = 1 << 30;
int mat[N][N], d[N][N], n;

void init()
{
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            d[i][j] = INF;
        }
        for(int j = 1; j < i; j++){
            d[i][j]  =INF;
        }
    }
}

int main()
{
    in >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            in >> mat[i][j];
        }
    }
    init();
    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                if(mat[i][k] + mat[k][j] < d[i][j]){
                    d[i][j] = mat[i][k] + mat[k][j];
                    ///pred[i][j] = pred[k]][j];
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            out << d[i][j] << " ";
        }
        out << "\n";
    }

    return 0;
}