Cod sursa(job #2428101)

Utilizator valentin11cCraciun Valentin-Gabriel valentin11c Data 3 iunie 2019 19:57:12
Problema Floyd-Warshall/Roy-Floyd Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.14 kb
#include <iostream>
#include<fstream>

using namespace std;
int NumberOfElements,PathMatrix[105][105];
void Read_Initial_Matrix()
{
    ifstream f("royfloyd.in");
    f>>NumberOfElements;
    for(int i=1;i<=NumberOfElements;i++)
    {
        for(int j=1;j<=NumberOfElements;j++)
        {
            f>>PathMatrix[i][j];
        }

    }

    f.close();
}
void Roy_Floyd()
{

    for(int k=1;k<=NumberOfElements;k++)
    {
        for(int i=1;i<=NumberOfElements;i++)
        {
            for(int j=1;j<=NumberOfElements;j++)
            {
               if(PathMatrix[i][k]!=0 && PathMatrix[k][j]!=0 || PathMatrix[i][j]==0)
                    PathMatrix[i][j]=min(PathMatrix[i][j],PathMatrix[i][k]+PathMatrix[k][j]);
            }
        }

    }
}
void Write_Path_Matrix()
{
    ofstream g("royfloyd.out");
 for(int i=1;i<=NumberOfElements;i++)
    {
        for(int j=1;j<=NumberOfElements;j++)
        {
            g<<PathMatrix[i][j]<<" ";
        }
        g<<"\n";

    }
    g.close();
}


int main()
{

    Read_Initial_Matrix();
    Roy_Floyd();
    Write_Path_Matrix();
    return 0;
}