Cod sursa(job #2218346)

Utilizator BiancaMariaVulsanVulsan Bianca Maria BiancaMariaVulsan Data 4 iulie 2018 12:06:35
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
#include <iostream>
#include <fstream>
#define inf 105
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int d[inf][inf], n;
int main()
{
    int i,j,k;
    f>>n;
    for(i=1; i<=n; i++)
    for(j=1; j<=n; j++)
        f>>d[i][j];
    for(k=1; k<=n; k++)
      for(i=1; i<=n; i++)
        for(j=1; j<=n; j++)
            d[i][j]=min(d[i][j], d[k][j]+d[i][k]);
    for(i=1; i<=n; i++)
    {for(j=1; j<=n; j++)
        g<<d[i][j]<<" ";
    g<<endl;}

    f.close();
    g.close();
    return 0;
}