Cod sursa(job #1757517)

Utilizator DoubleNyNinicu Cristian DoubleNy Data 15 septembrie 2016 10:47:44
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <bits/stdc++.h>
#define ll long long
#define lli long long int
#define endl "\n"
#include <stdio.h>
using namespace std;
int cost[300][300],maxim[300][300],n;

void RoyFloyd()
{
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                    if(cost[i][j] > cost[i][k] + cost[k][j])
                       cost[i][j] = cost[i][k] + cost[k][j];
}

int main()
{
    cin >> n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            cin >> cost[i][j];
    RoyFloyd();
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            cout << cost[i][j] << ' ';
        cout << endl;
    }
    return (0);
}