This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "meetings.h"
#pragma GCC target("sse,sse2,avx2")
#pragma GCC optimize("unroll-loops,O2")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 2e3+10,mod = 998244353,inf = 1e9+10,sq = 700;
inline int mkay(int a,int b){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int a,int k){
if (k < 0) return 0;
int z = 1;
while (k){
if (k&1) z = 1ll*z*a%mod;
a = 1ll*a*a%mod;
k /= 2;
}
return z;
}
int noob;
vector<int> tmp[N][N];
bool cmp(int u,int v){
int x = Query(u,v,noob);
if (x == u) return 1;
return 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void dojob(vector<int> ve,int dep = 0){
int n = ve.size();
if (n == 1) return;
if (n == 2){
if (ve[1] < ve[0]) swap(ve[0],ve[1]);
Bridge(ve[0],ve[1]);
return;
}
int ind = rng()%(n-1),ind2 = rng()%(n-ind-1)+ind+1;
int u = ve[ind],v = ve[ind2];
vector<int> path;
tmp[u][dep].pb(u);
tmp[v][dep].pb(v);
rep(i,0,n){
if (i == ind || i == ind2) continue;
int w = ve[i];
int x = Query(u,v,w);
if (x == w) path.pb(w);
tmp[x][dep].pb(w);
}
for (int w : ve) if (!tmp[w][dep].empty()){
dojob(tmp[w][dep],dep+1);
tmp[w][dep].clear();
}
if (path.empty()){
Bridge(min(u,v),max(u,v));
return;
}
noob = u;
sort(all(path),cmp);
int sz = path.size();
Bridge(min(u,path[0]),max(u,path[0]));
Bridge(min(v,path.back()),max(v,path.back()));
rep(i,1,sz){
int x = path[i],y = path[i-1];
if (x > y) swap(x,y);
Bridge(x,y);
}
}
void Solve(int n){
vector<int> ve;
rep(i,0,n) ve.pb(i);
dojob(ve);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |