Problem Statement

Given a undirected unweighted acyclic graph, the root is always one (1), given inital and final states for each node in graph, the state is binary (either 0 or 1) . Do the following operations and return nodes on which the operations has performed in sorted ascending order.

  • If the inital state of a node is not same as final state , the flip the binary state of the node and all its decendents at which occur at odd levels. (Level indexing start from 1).
  • If the inital state of a node is same as final state, don't return it in answer.

Input :

The first contains the integer N the number of vertexes.

Next contains edges between vertexes/nodes.

Last but one line contains inital states of N vertexes.

Last line contains final states of N vertex.

Sample Input

5
1 2
1 4
2 3
4 5
1 0 0 1 1
0 1 0 1 1

Sample Output

1 2 3 5

Sample Explanation

  • Since 1's inital states is 1 and final state is 0 , flip one's and all its descendents which occur at odd level from one. Which are 3 and 5 (whose inital states are now 1 and 0 respectively).
  • Now 2's inital states is 0 and final state is 1 , flip two and all its descendents which occur at odd levels , i.e., no nodes.
  • Flip 3's and 5's state.
    Answer : [1,2,3,5]
Comments (4)