Pagini recente » Cod sursa (job #49135) | Cod sursa (job #2495974) | Cod sursa (job #2403024) | Cod sursa (job #2605920) | Cod sursa (job #2769437)
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
/*********************************************/
/// INPUT / OUTPUT
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
/*********************************************/
/// GLOBAL DECLARATIONS
int N, M;
/*********************************************/
/// FUNCTIONS
void Floyd();
void Dijkstra();
void Bellman();
/*********************************************/
///-------------------------------------------------------
inline void Floyd()
{
f >> N;
int mat[N + 5][N + 5];
for (int i = 1 ; i <= N ; ++ i)
for (int j = 1 ; j <= N ; ++ j)
{
f >> mat[i][j];
if (i == j)
continue;
if (!mat[i][j])
mat[i][j] = INF;
}
for (int k = 1 ; k <= N ; ++ k)
{
for (int i = 1 ; i <= N ; ++ i)
{
for (int j = 1 ; j <= N ; ++ j)
{
mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
}
}
}
for (int i = 1 ; i <= N ; ++ i)
{
for (int j = 1 ; j <= N ; ++ j)
{
if (mat[i][j] == INF)
mat[i][j] = 0;
g << mat[i][j] << " ";
}
g << "\n";
}
}
///-------------------------------------------------------
inline void Dijkstra()
{
}
///-------------------------------------------------------
inline void Bellman()
{
}
///-------------------------------------------------------
int main()
{
Floyd();
// Dijkstra();
// Bellman();
return 0;
}