Submission #75117

#TimeUsernameProblemLanguageResultExecution timeMemory
75117imeimi2000Highway Tolls (IOI18_highway)C++17
100 / 100
328 ms9868 KiB
#include "highway.h" #include <queue> #include <algorithm> using namespace std; typedef long long llong; int n, m; vector<int> edge[90000]; int dist1[90000]; int dist2[90000]; void bfs(int dist[], int S) { for (int i = 0; i < n; ++i) dist[i] = n; queue<int> q; dist[S] = 0; q.push(S); while (!q.empty()) { int x = q.front(); q.pop(); for (int i : edge[x]) { if (dist[i] < n) continue; dist[i] = dist[x] + 1; q.push(i); } } } int ch[90000]; void find_pair(int N, vector<int> U, vector<int> V, int A, int B) { n = N; m = U.size(); llong d; { vector<int> q(m, 0); d = ask(q); } int L, R; { int s = 0, e = m - 1; while (s < e) { int md = (s + e) / 2; vector<int> q(m, 0); for (int i = 0; i <= md; ++i) q[i] = 1; if (ask(q) != d) e = md; else s = md + 1; } L = U[s]; R = V[s]; } for (int i = 0; i < m; ++i) { edge[U[i]].push_back(V[i]); edge[V[i]].push_back(U[i]); } bfs(dist1, L); bfs(dist2, R); vector<int> LP, RP; for (int i = 0; i < n; ++i) { if (dist1[i] < dist2[i]) LP.push_back(i); if (dist1[i] > dist2[i]) RP.push_back(i); } sort(LP.begin(), LP.end(), [&](int i, int j) { return dist1[i] > dist1[j]; }); sort(RP.begin(), RP.end(), [&](int i, int j) { return dist2[i] > dist2[j]; }); { int s = 0, e = LP.size() - 1; while (s < e) { int md = (s + e) / 2; vector<int> q(m); for (int i = 0; i < n; ++i) ch[i] = 0; for (int i = 0; i <= md; ++i) ch[LP[i]] = 1; for (int i = 0; i < m; ++i) q[i] = ch[U[i]] ^ ch[V[i]]; if (ask(q) != d) e = md; else s = md + 1; } L = LP[s]; } { int s = 0, e = RP.size() - 1; while (s < e) { int md = (s + e) / 2; vector<int> q(m); for (int i = 0; i < n; ++i) ch[i] = 0; for (int i = 0; i <= md; ++i) ch[RP[i]] = 1; for (int i = 0; i < m; ++i) q[i] = ch[U[i]] ^ ch[V[i]]; if (ask(q) != d) e = md; else s = md + 1; } R = RP[s]; } answer(L, R); }
#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...