Cod sursa(job #1757520)

Utilizator DoubleNyNinicu Cristian DoubleNy Data 15 septembrie 2016 10:49:12
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 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;
ifstream fin("royfloyd.in");
ofstream fou("royfloyd.out");
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()
{
    fin >> n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            fin >> cost[i][j];
    RoyFloyd();
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            fou << cost[i][j] << ' ';
        fou << endl;
    }
    return (0);
}