#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef string str;
int findEgg(int n, vector <pair <int, int>> edges) {
vector <int> g[n + 1];
int par[n + 1], sz[n + 1];
vector <bool> used(n + 1, false);
for (auto [a, b] : edges) {
g[a].push_back(b);
g[b].push_back(a);
}
function <void(int, int)> prepare = [&](int v, int p) {
par[v] = p;
sz[v] = 1;
for (int to : g[v]) {
if (to == p) {
continue;
}
prepare(to, v);
sz[v] += sz[to];
}
};
prepare(1, -1);
function <int(int, int)> get_centroid = [&](int v, int p) {
for (int to : g[v]) {
if (to == p || used[to]) {
continue;
}
if (sz[to] * 2 > n) {
return get_centroid(to, v);
}
}
return v;
};
vector <int> subtree;
function <void(int, int)> get_subtree = [&](int v, int p) {
subtree.push_back(v);
for (int to : g[v]) {
if (to == p || used[to]) {
continue;
}
get_subtree(to, v);
}
};
int root = 1;
do {
subtree.clear();
int centroid = get_centroid(root, par[root]);
get_subtree(centroid, par[centroid]);
if (query(subtree)) {
root = centroid;
} else {
used[centroid] = true;
int cur = centroid;
while (par[cur] != -1) {
sz[par[cur]] -= sz[centroid];
cur = par[cur];
}
}
} while ((int)subtree.size() > 1);
return subtree.back();
}
Compilation message
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:54:9: error: 'query' was not declared in this scope
54 | if (query(subtree)) {
| ^~~~~