Cod sursa(job #3192631)

Utilizator VerestiucAndreiVerestiuc Andrei VerestiucAndrei Data 13 ianuarie 2024 09:27:27
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin ("royfloyd.in");
ofstream fout ("royfloyd.out");
int n;
int mat[105][105];
int cost[105][105];
int main()
{
    fin>>n;
    for (int i=1; i<=n; i++)
        for (int j=1; j<=n; j++)
            fin>>mat[i][j], cost[i][j]=mat[i][j];

    for (int z=1; z<=n; z++) {
        for (int x=1; x<=n; x++) {
            for (int y=1; y<=n; y++)
                if (cost[x][z] && cost[z][y] && cost[x][z]+cost[z][y]<cost[x][y])
                    cost[x][y]=cost[x][z]+cost[z][y];
        }
    }

    for (int i=1; i<=n; i++) {
        for (int j=1; j<=n; j++)
            fout<<cost[i][j]<<' ';
        fout<<'\n';
    }
    return 0;
}