Pagini recente » Cod sursa (job #1823005) | Cod sursa (job #1153893) | Cod sursa (job #1358536) | Cod sursa (job #1903767) | Cod sursa (job #1379519)
/*
Keep It Simple!
*/
#include <fstream>
#include <vector>
#include <list>
#include <stack>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
ifstream f("royfloyd.in");
ofstream g("royfloyd.out");
#define ll long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int kMaxN = 105;
const int inf = 0x3f3f3f3f;
int n;
int mat[kMaxN][kMaxN];
void Solve()
{
f >> n;
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
f >> mat[i][j];
for(int k=1; k<=n; ++k)
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
if(i!=j && mat[i][k] && mat[k][j])
if((mat[i][j] > mat[i][k] + mat[k][j]) || !mat[i][j])
mat[i][j] = mat[i][k] + mat[k][j];
for(int i=1;i<=n;++i)
{
for(int j=1;j<=n;++j)
g << mat[i][j] << ' ';
g << '\n';
}
}
int main()
{
Solve();
return 0;
}