제출 #288267

#제출 시각아이디문제언어결과실행 시간메모리
288267andrew통행료 (IOI18_highway)C++17
6 / 100
185 ms24828 KiB
#include <bits/stdc++.h> #include "highway.h" #define fi first #define se second #define p_b push_back #define m_p make_pair #define sz(x) (int)x.size() #define pii pair <int, int> #define all(x) x.begin(),x.end() using namespace std; typedef long long ll; vector < vector <pii> > v; vector <int> p, tin, tout, nm, order, deep; vector <vector <int> > level; int _timer; void dfs(int x, int pr, int gl){ p[x] = pr; tin[x] = ++_timer; order.p_b(x); deep[x] = gl; level[gl].p_b(x); for(auto to : v[x])if(to.fi != pr){ dfs(to.fi, x, gl + 1); nm[to.fi] = to.se; } tout[x] = _timer; } void find_pair(int n, vector<int> U, vector<int> V, int A, int B) { int m = U.size(); _timer = 0; tin.resize(n); tout.resize(n); p.resize(n); v.resize(n); nm.resize(n); deep.resize(n); level.resize(n); vector <int> w(m, 0); ll dist = ask(w); ll Len = dist / A; for(int i = 0; i < m; i++){ v[U[i]].p_b({V[i], i}); v[V[i]].p_b({U[i], i}); } dfs(0, -1, 0); int Lca = -1; int l = 0, r = n - 1; while(l < r){ int mid = (l + r + 1) >> 1; fill(all(w), 0); for(int i = 1; i <= mid; i++)w[nm[order[i]]] = 1; if(ask(w) != dist)r = mid - 1; else l = mid; } Lca = order[l]; l = 0, r = n; while(l < r){ int mid = (l + r) >> 1; fill(all(w), 0); for(int i = mid + 1; i < n; i++)w[nm[order[i]]] = 1; if(ask(w) != dist)l = mid + 1; else r = mid; } int S = order[l]; int T = -1; int ost = Len - (deep[S] - deep[Lca]); vector <int> mb; for(int i : level[ost + deep[Lca]]){ if(tin[Lca] <= tin[i] && tout[i] <= tout[Lca])mb.p_b(i); } l = 0, r = sz(mb) - 1; while(l < r){ int mid = (l + r) >> 1; fill(all(w), 0); for(int i = 1; i < tin[mb[mid]]; i++)w[nm[order[i]]] = 1;; if(ask(w) < dist + ost * (B - A))l = mid + 1; else r = mid; } T = mb[l]; answer(S, T); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...