Cod sursa(job #3285022)

Utilizator PsyDuck1914Feraru Rares-Serban PsyDuck1914 Data 12 martie 2025 14:16:07
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 kb
#include <bits/stdc++.h>

using namespace std;

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

const int NMAX = 1e2;

int n, dp[NMAX + 1][NMAX + 1], a[NMAX + 1][NMAX + 1];

int main()
{
    
    f >> n;
    
    for(int i=1; i<=n; i++){
        
        for(int j=1; j<=n; j++){
            
            f >> a[i][j];
            
            dp[i][j] = a[i][j];
            
            if(a[i][j] == 0 and i!=j)
                dp[i][j] = 2e9;
                
            //cout << dp[i][j] << endl;
            
        }
        
    }
    
    for(int k=1; k<=n; k++)
        for(int i=1; i<=n; i++)
            for(int j=1; j<=n; j++)
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                
    for(int i=1; i<=n; i++){
        
        for(int j=1; j<=n; j++){
            
            if(dp[i][j] == 0)
                g << 0 << " ";
            else g << dp[i][j] << " ";
            
        }
        
        cout << "\n";
        
    }
        
    return 0;
}