标签:acm 贪心 codeforces dfs
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; }
Codeforces Round #245 (Div. 1)——Xor-tree,布布扣,bubuko.com
Codeforces Round #245 (Div. 1)——Xor-tree
标签:acm 贪心 codeforces dfs
原文地址:http://blog.csdn.net/wty__/article/details/25607945