429A.md (1991B)
1 Source: https://codeforces.com/problemset/problem/429/A 2 3 A. Xor-tree 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 Iahub is very proud of his recent discovery, propagating trees. Right now, he invented a new tree, called xor-tree. After this new revolutionary discovery, he invented a game for kids which uses xor-trees. 22 23 The game is played on a tree having *n* nodes, numbered from 1 to *n*. Each node *i* has an initial value *init**i*, which is either 0 or 1. The root of the tree is node 1. 24 25 One can perform several (possibly, zero) operations on the tree during the game. The only available type of operation is to pick a node *x*. Right after someone has picked node *x*, the value of node *x* flips, the values of sons of *x* remain the same, the values of sons of sons of *x* flips, the values of sons of sons of sons of *x* remain the same and so on. 26 27 The goal of the game is to get each node *i* to have value *goal**i*, which can also be only 0 or 1. You need to reach the goal of the game by using minimum number of operations. 28 29 Input 30 31 The first line contains an integer *n* (1 ≤ *n* ≤ 105). Each of the next *n* - 1 lines contains two integers *u**i* and *v**i* (1 ≤ *u**i*, *v**i* ≤ *n*; *u**i* ≠ *v**i*) meaning there is an edge between nodes *u**i* and *v**i*. 32 33 The next line contains *n* integer numbers, the *i*-th of them corresponds to *init**i* (*init**i* is either 0 or 1). The following line also contains *n* integer numbers, the *i*-th number corresponds to *goal**i* (*goal**i* is either 0 or 1). 34 35 Output 36 37 In the first line output an integer number *cnt*, representing the minimal number of operations you perform. Each of the next *cnt* lines should contain an integer *x**i*, representing that you pick a node *x**i*. 38 39 Examples 40 41 Input 42 43 ``` 44 10 45 2 1 46 3 1 47 4 2 48 5 1 49 6 2 50 7 5 51 8 6 52 9 8 53 10 5 54 1 0 1 1 0 1 0 1 0 1 55 1 0 1 0 0 1 1 1 0 1 56 ``` 57 58 Output 59 60 ``` 61 2 62 4 63 7 64 ```