Pagini recente » Cod sursa (job #219131) | Istoria paginii runda/sacou | Cod sursa (job #3205860) | Cod sursa (job #3280573) | Cod sursa (job #2748527)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;
#ifdef Wi_TEST
template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
out << "(" << p.first << ", " << p.second << ")";
out.flush();
return out;
}
#define deb(x) cout << #x << " = " << x << endl;
#else
#define deb(x)
#define cin fin
#define cout fout
#endif
const long long MOD = 1e9+7;
#define N 105
int A[N][N];
int main() {
ios_base::sync_with_stdio(false);
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
cin >> n;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
cin >> A[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) && A[i][k] && A[k][j]) {
if(A[i][j])
A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
else
A[i][j] = A[i][k] + A[k][j];
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j)
cout << A[i][j] << ' ';
cout.put('\n');
}
return 0;
}