Cod sursa(job #2561031)

Utilizator moise_alexandruMoise Alexandru moise_alexandru Data 28 februarie 2020 15:26:17
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("royfloyd.in");
ofstream out("royfloyd.out");
const int maxn = 105;
int cost[maxn][maxn];
int main()
{
    int n;
    in >> n;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            in >> cost[i][j];
            if(cost[i][j] == 0)
                cost[i][j] = (1 << 25);
        }
    }
    for(int k = 1; k <= n; k++)
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                if(i != k && i != j && k != j && cost[i][j] > cost[i][k] + cost[k][j])
                    cost[i][j] = cost[i][k] + cost[k][j];
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(cost[i][j] == (1 << 25))
                out << 0 << " ";
            else
                out << cost[i][j] << " ";
        }
        out << "\n";
    }
    return 0;
}