From the top down to the first different node, it will flip, and Recursion will do ....
A. Xor-treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Iahub is very proud of his recent discovery, propagating trees. right now, he has Ted a new tree, called xor-tree. after this new revolutionary discovery, he has Ted a game for kids which uses xor-trees.
The game is played on a tree havingNNodes, numbered from 1N. Each nodeIHas an initial valueInitI, Which is either 0 or 1. The root of the tree is node 1.
One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a nodeX. Right after someone has picked nodeX, The value of nodeXFlips, the values of sonsXRemain the same, the values of sonsXFlips, the values of sonsXRemain the same and so on.
The goal of the game is to get each nodeITo have valueGoalI, Which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations.
Input
The first line contains an integerN(1? ≤?N? ≤? 105). Each of the nextN? -? 1 lines contains two integersUIAndVI(1? ≤?UI,?VI? ≤?N;UI? ?VI) Meaning there is an edge between nodesUIAndVI.
The next line containsNInteger numbers,I-Th of them correspondsInitI(InitIIs either 0 or 1). The following line also containsNInteger numbers,I-Th number correspondsGoalI(GoalIIs either 0 or 1 ).
Output
In the first line output an integer numberCnt, Representing the minimal number of operations you perform. Each of the nextCntLines shoshould contain an integerXI, Representing that you pick a nodeXI.
Sample test (s) input
102 13 14 25 16 27 58 69 810 51 0 1 1 0 1 0 1 0 11 0 1 0 0 1 1 1 0 1
Output
247
#include
#include
#include
#include #include
using namespace std;int n,init[110000],goal[110000];vector
g[110000],ans;void dfs(int u,int fa,int c1,int c2){ if(c1) init[u]^=1; if(init[u]!=goal[u]) { c1^=1; ans.push_back(u); } for(int i=0;i