RT,截取了关键代码,vscode 判断是箭头那一行 RE 了
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 111, inf = 1e9 + 7;
int n, m, tot, ans, rt, sum, minn, cnt;
int val[N], H[N], siz[N], fa[N], dep[N], pos[N], st[N << 1][21], lg2[N << 1];
bool vis[N];
vector<int> c[2][N];
int h[N], to[N << 1], ne[N << 1], id = 0;
void add(int x, int y)
{
to[++id] = y, ne[id] = h[x], h[x] = id;
}
void dfs0(int u, int f)
{
st[++cnt][0] = u, pos[u] = cnt;
for (int i = h[u]; i; i = ne[i])//<-----
{
int v = to[i];
if (v == f)
continue;
dep[v] = dep[u] + 1,
dfs0(v, u), st[++cnt][0] = u;
}
}
int main()
{
freopen("P6329_1.in", "r", stdin);
ios::sync_with_stdio(0),
cin.tie(0), cout.tie(0);
int opt, x, y;
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> val[i];
for (int i = 1; i < n; ++i)
cin >> x >> y, add(x, y), add(y, x);
dfs0(1, 0);
return 0;
}