Cod sursa(job #2170299)

Utilizator LuizaPatroescuPatroescu Luiza LuizaPatroescu Data 14 martie 2018 23:18:51
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
#include <fstream>

using namespace std;

const int maxi=15000;

int c[101][101],n,m;

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

void citire()
{
     int x,y,cost;

  f >> n;

  for(int i=1; i<=n; i++)
    for(int j=1; j<=n; j++)
       {

        f>>c[i][j];
           if(c[i][j]==0 & i!=j) c[i][j]=maxi;
       }
}

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

void afis()
{
  for(int i=1; i<=n; i++)
      {
      for(int j=1; j<=n; j++)
	 if( c[i][j] == maxi ) g<<"0 ";
	 else g << c[i][j] <<" ";
	 g<<endl;
     }
}

int main()
 { citire();
   rf();
   afis();
}