版本比较
Clever Girl
正文
增加 3 行删除 3 行
44 行未改动454647484949505152535453545556575844 行未改动int main() { freopen(".in", "r", stdin); freopen(".out", "w", stdout); ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i ++) cin >> H[i], pos[H[i]] = i, fa[i] = i; for (int i = 1; i <= n; i ++) cin >> H[i], pos[H[i]] = i, fa[i] = i; for (int i = 1, u, v; i < n; i ++) cin >> u >> v, G[u].push_back(v), G[v].push_back(u); top[1] = 1; DFS1(1, 0); DFS2(1, 0); for (int i = 1; i <= n; i ++) { for (int v : G[pos[i]]) if (H[v] < i) vec[pos[i]].push_back(Find(v)), fa[Find(v)] = pos[i]; for (int v : G[pos[i]]) if (H[v] < i) vec[pos[i]].push_back(Find(v)), fa[Find(v)] = pos[i]; } DFS3(Find(1), 0); cout << Ans << "\n"; return 0;}```