时间:2021-07-01 10:21:17 帮助过:17人阅读
const int MAXN = 110000;VI G[MAXN], ans;int now[MAXN], goal[MAXN];void dfs(int u, int fa, int a, int b){ int rev = ((now[u] ^ a) != goal[u]); if (rev) { ans.push_back(u); a ^= 1; } REP(i, G[u].size()) { int v = G[u][i]; if (v != fa) dfs(v, u, b, a); }}int main(){ // freopen("in.txt", "r", stdin); int n, a, b; while (~RI(n)) { FE(i, 0, n) G[i].clear(); ans.clear(); REP(i, n - 1) { RII(a, b); G[a].push_back(b); G[b].push_back(a); } FE(i, 1, n) RI(now[i]); FE(i, 1, n) RI(goal[i]); dfs(1, 0, 0, 0); WI(ans.size()); REP(i, ans.size()) WI(ans[i]); } return 0;}