Pagini recente » Cod sursa (job #2655143) | Cod sursa (job #2974597) | Cod sursa (job #2289847) | Cod sursa (job #2846501) | Cod sursa (job #2628099)
#include <bits/stdc++.h>
using namespace std;
/******************************************/
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
/******************************************/
//variabile globale
int n;
int dist[101][101];
/******************************************/
///---------------------------------------------
inline void readInput()
{
f>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
f>>dist[i][j];
if(dist[i][j]==0) dist[i][j] = 1000000000;
}
}
}
///---------------------------------------------
inline void Solution()
{
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(dist[i][j] > dist[i][k] + dist[k][j])
{
dist[i][j] = dist[i][k] + dist[k][j];
}
}
}
}
}
///---------------------------------------------
inline void Afisare()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(dist[i][j]== 1000000000 || i==j) g<<"0"<<" ";
else g<<dist[i][j]<<" ";
}
g<<"\n";
}
}
///---------------------------------------------
int main()
{
readInput();
Solution();
Afisare();
return 0;
}