Cod sursa(job #2425764)

Utilizator cochinteleandreeaCochintele Andreea Elena cochinteleandreea Data 25 mai 2019 00:53:01
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
using namespace std;

int G[101][101];
 ifstream f("royfloyd.in");
ofstream g ( "royfloyd.out");
int main(){

  int i, j, k, n;

  f >> n;
  for(i=0;i<n;i++)
   for(j=0;j<n;j++)
      f >> G[i][j];



 for(k=0;k<n;k++)
     for(j=0;j<n;j++)
      for(i=0;i<n;i++)
        if ( G[i][k] && G[k][j] && i != j  && ( G[i][j] > G[i][k] + G[k][j] || !G[i][j]))
          G[i][j] = ( G[i][k] + G[k][j]);


  for(i=0;i<n;i++){
   for(j=0;j<n;j++)
      g << G[i][j] << " ";
    g << "\n";
  }


  return 0;
}