제출 #513839

#제출 시각아이디문제언어결과실행 시간메모리
513839fatemetmhrMeetings (JOI19_meetings)C++17
100 / 100
971 ms12616 KiB
// ~Be name khoda~ // #include "meetings.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define fi first #define se second #define cl clear #define endll '\n' mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 1e6 + 10; const int maxn5 = 5e5 + 10; const int maxnt = 1.2e6 + 10; const int maxn3 = 1e3 + 10; const int mod = 1e9 + 7; const ll inf = 2e18; int n, per[maxn5]; vector <int> adj[maxn5], tmp, av; int mx[maxn5], sz[maxn5], rev[maxn5]; bool rem[maxn5], mark[maxn5]; int lev = 0; inline void remo(int a, int b){ tmp.clear(); for(auto u : adj[a]) if(u != b) tmp.pb(u); adj[a].clear(); for(auto u : tmp) adj[a].pb(u); return; } inline void dfs(int v, int par){ sz[v] = 1; mx[v] = 0; av.pb(v); for(auto u : adj[v]) if(u != par && !rem[u]){ dfs(u, v); mx[v] = max(mx[v], sz[u]); sz[v] += sz[u]; } return; } inline void add(int r, int v){ lev++; //cout << "adding " << r << ' ' << v << endl; av.clear(); dfs(r, -1); int c = r; for(auto u : av) if(max(mx[u], int(av.size()) - sz[u]) < max(mx[c], int(av.size()) - sz[c])) c = u; int sub = -1; //cout << "centroid " << c << endl; assert(lev <= 11); for(auto uu : adj[c]) if(!rem[uu]){ int u = uu; int t = Query(per[c], per[u], per[v]); t = rev[t]; if(t == v){ //cout << "right " << u << endl; remo(u, c); remo(c, u); adj[u].pb(v); adj[c].pb(v); adj[v].pb(u); adj[v].pb(c); return; } else if(t == u){ sub = u; break; } else if(t != c){ remo(u, c); remo(c, u); adj[u].pb(t); adj[v].pb(t); adj[c].pb(t); adj[t].pb(u); adj[t].pb(c); adj[t].pb(v); mark[t] = true; return; } } //cout << "ok " << sub << endl; if(sub != -1){ rem[c] = true; add(sub, v); return; } adj[c].pb(v); adj[v].pb(c); } void Solve(int nn){ n = nn; for(int i = 0; i < n; i++){ per[i] = i; } shuffle(per, per + n, rng); for(int i = 0; i < n; i++){ rev[per[i]] = i; //cout << i << ' ' << per[i] << endl; } for(int i = 1; i < n; i++) if(!mark[i]){ fill(rem, rem + n + 5, false); lev = 0; add(0, i); mark[i] = true; } for(int i = 0; i < n; i++) for(auto u : adj[i]){ //cout << "edge " << i << ' '<< u << ' ' << per[i] << ' ' << per[u] << endl; if(per[i] < per[u]) Bridge(per[i], per[u]); } return; } /* 4 0 3 2 3 1 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...