Pagini recente » Cod sursa (job #2081901) | Cod sursa (job #2427471) | Cod sursa (job #2148523) | Cod sursa (job #870986) | Cod sursa (job #2613365)
//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/
#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
#define in fin
#define out fout
using namespace std;
typedef long long ll;
typedef unsigned int uint;
const int nmax = 300005;
const ll linf = LLONG_MAX;
const int mod = 1e9+7;
const int inf = INT_MAX;
ifstream fin("royfloyd.in");
ofstream fout("royfloyd.out");
int n;
int d[105][105];
int main(){
in >> n;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
in >> d[i][j];
}
}
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
{
if(d[i][k] != 0 && d[k][j] && i != j){
if(d[i][j] != 0){
d[i][j] = min(d[i][j] , d[i][k]+d[k][j]);
}else{
d[i][j] = d[i][k] + d[k][j];
}
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
out << d[i][j] << ' ';
}
out << '\n';
}
}