（题目大意来自洛谷题解某一篇）

# 代码

#include <bits/stdc++.h>
#define ms(a, b) memset(a, b, sizeof(a))
#define ll long long
#define ull unsigned long long
#define ms(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define db double
#define Pi acos(-1)
#define eps 1e-8
#define pq priority_queue
#define N 200005
using namespace std;
template <typename T> T power(T x, T y, T mod) { x %= mod; T res = 1; for (; y; y >>= 1) { if (y & 1) res = (res * x) % mod; x = (x * x) % mod; } return res; }
template <typename T> void read(T &x) {
x = 0; T fl = 1; char ch = 0;
for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') fl = -1;
for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
x *= fl;
}
template <typename T> void write(T x) {
if (x < 0) x = -x, putchar('-');
if (x > 9) write(x / 10); putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) { write(x); puts(""); }
vector<int> g[N];
int n, val[N], id[N], tot;
pq<int> q[N];
void merge(int &a, int &b) {
if (q[a].size() < q[b].size()) swap(a, b);
int tot = 0; static int c[N];
while (!q[b].empty()) c[++ tot] = max(q[a].top(), q[b].top()), q[a].pop(), q[b].pop();
for (int i = 1; i <= tot; i ++) q[a].push(c[i]);
}
void dfs(int u) {
id[u] = ++ tot;
for (int i = 0; i < g[u].size(); i ++) {
int v = g[u][i];
dfs(v);
merge(id[u], id[v]);
}
q[id[u]].push(val[u]);
}
int main() {
tot = 0;
}