Submission #255312

#TimeUsernameProblemLanguageResultExecution timeMemory
255312ErkhemkhuuHighway Tolls (IOI18_highway)C++17
0 / 100
74 ms20856 KiB
#include <bits/stdc++.h> #include <highway.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define F first #define S second const int N = 150005; pair <ll, ll> par[N]; vector <int> w; vector <vector <pair <ll, ll> > > adj(N); ll flat[N], timer; void dfs(ll v, ll p) { flat[timer++] = v; for(auto &u: adj[v]) { if(u.F == p) continue; par[u.F] = {v, u.S}; dfs(u.F, v); } return; } void find_pair(int n, vector <int> u, vector <int> v, int a, int b) { ll i, m, max_cost, l, r, mid, s, t; m = u.size(); for(i = 0; i < m; i++) { adj[u[i]].pb({v[i], i}); adj[v[i]].pb({u[i], i}); } dfs(0, -1); w.resize(m, 1); max_cost = ask(w); w.resize(m, 0); l = 1; r = m; while(l != r) { mid = (l + r) / 2; for(i = l; i <= mid; i++) w[par[flat[i]].S] = 1; if(ask(w) >= max_cost) { r = mid; for(i = l; i <= mid; i++) w[par[flat[i]].S] = 0; } else l = mid + 1; } s = flat[l]; w.resize(m, 0); timer = 0; memset(flat, 0, sizeof(flat)); memset(par, 0, sizeof(par)); dfs(s, -1); l = 1; r = m; while(l != r) { mid = (l + r) / 2; for(i = l; i <= mid; i++) w[par[flat[i]].S] = 1; if(ask(w) >= max_cost) { r = mid; for(i = l; i <= mid; i++) w[par[flat[i]].S] = 0; } else l = mid + 1; } t = flat[l]; assert(s >= 0 && s < n && t >= 0 && t < n); answer(s, t); return; }
#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...