Pagini recente » Cod sursa (job #159681) | Cod sursa (job #2424252) | Cod sursa (job #536691) | Cod sursa (job #334655) | Cod sursa (job #2556424)
#include <fstream>
#define INF 0xf3f3f3f3
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
int mat[105][105], n;
void read()
{
f>>n;
for(int i = 0; i<n; ++i)
{
for(int j = 0; j<n; ++j)
{
f>>mat[i][j];
if(mat[i][j] == 0)
mat[i][j] = INF;
}
}
}
void solve()
{
for(int k = 0; k<n; ++k)
{
for(int i = 0; i<n; ++i)
{
for(int j = 0; j<n; ++j)
{
mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
}
}
}
}
void print()
{
for(int i = 0; i<n; ++i)
{
for(int j = 0; j<n; ++j)
{
g<<mat[i][j]<<" ";
}
}
}
int main()
{
read();
solve();
print();
return 0;
}