Pagini recente » Cod sursa (job #1536684) | Cod sursa (job #389279) | Cod sursa (job #2717585) | Cod sursa (job #3153782) | Cod sursa (job #2509820)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int matAdiacenta[105][105];
int n;
void citire()
{
f>>n;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
f>>matAdiacenta[i][j];
}
void Warshall(int a[105][105])
{
for(int k=1; k<=n; k++)
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
if(i!=j && j!=k && i!=k && a[i][k]!=0 && a[k][j]!=0)
if(a[i][j]==0 || a[i][k]+a[k][j]<a[i][j])
a[i][j]=a[i][k]+a[k][j];
}
void afisare()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
g<<matAdiacenta[i][j]<<" ";
g<<"\n";
}
}
int main()
{
citire();
Warshall(matAdiacenta);
afisare();
return 0;
}