Cod sursa(job #2222262)

Utilizator Andrei-27Arhire Andrei Andrei-27 Data 16 iulie 2018 19:06:46
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("bulfei.in");
ofstream g("bulfei.out");
void citire(int n, int a[100][100]){
for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
        f>>a[i][j];}
void roy_floyd(int n,int a[100][100]){
for(int k=0;k<n;k++) for(int i=0;i<n;i++) for(int j=0;j<n;j++)
            if(i!=j&&a[i][k]&&a[k][j]&&(a[i][j]>a[i][k]+a[k][j])||!a[i][j]&&i!=j) a[i][j]=a[i][k]+a[k][j];}
void afisare (int n,int a[100][100]){
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) g<<a[i][j]<<" ";
        g<<"\n";}}
int main(){
    int i,j,n,a[100][100];
    f>>n;
    citire(n,a);
    roy_floyd(n,a);
    afisare(n,a);

 return 0;}