Submission #1237397

#TimeUsernameProblemLanguageResultExecution timeMemory
1237397TimoshHighway Tolls (IOI18_highway)C++20
11 / 100
322 ms327680 KiB
#include "bits/stdc++.h" #include "highway.h" using namespace std; void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { int M = U.size(); vector<int> d(N), w(M); int D = ask(w); vector<vector<int>> g(N); for (int i = 0; i < M; i++) { g[U[i]].push_back(V[i]); g[V[i]].push_back(U[i]); } auto dfs = [&](auto dfs, int node, int par) -> void { for (auto &x : g[node]) { if (x == par) continue; d[x] = d[node] + 1; dfs(dfs, x, node); } }; dfs(dfs, 0, -1); int a = 0; int l = 0, r = N; while (l <= r) { int m = (l + r) / 2; for (int i = 0; i < M; i++) w[i] = max(d[U[i]], d[V[i]]) > m; int x = ask(w); if (x == D) r = m - 1; else a = m, l = m + 1; } a++; vector<int> cands; for (int i = 0; i < M; i++) if (max(d[U[i]], d[V[i]]) == a) cands.push_back(i); while (cands.size() > 1) { int m = cands.size() / 2; for (auto &i : w) i = 0; for (int j = 0; j < m; j++) w[cands[j]] = 1; int x = ask(w); vector<int> R; while (cands.size() > m) R.push_back(cands.back()), cands.pop_back(); if (x == D) cands = R; } int b = (d[V[cands[0]]] > d[U[cands[0]]] ? V[cands[0]] : U[cands[0]]); d[b] = 0; a = l = 0, r = N; dfs(dfs, b, -1); while (l <= r) { int m = (l + r) / 2; for (int i = 0; i < M; i++) w[i] = max(d[U[i]], d[V[i]]) > m; int x = ask(w); if (x == D) r = m - 1; else a = m, l = m + 1; } a++; cands.clear(); for (int i = 0; i < M; i++) if (max(d[U[i]], d[V[i]]) == a) cands.push_back(i); while (cands.size() > 1) { int m = cands.size() / 2; for (auto &i : w) i = 0; for (int j = 0; j < m; j++) w[cands[j]] = 1; int x = ask(w); vector<int> R; while (cands.size() > m) R.push_back(cands.back()), cands.pop_back(); if (x == D) cands = R; } int c = (d[V[cands[0]]] > d[U[cands[0]]] ? V[cands[0]] : U[cands[0]]); answer(c, b); }
#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...