A tree of n
nodes is an undirected connected graph having (n - 1)
edges.
Given an undirected tree comprising of tree_nodes
number of nodes numbered from 0
to tree_nodes - 1
, and rooted at node 0
. Each node has an initially binary value (0 or 1)
represented by the array initiall, and an expected binary value represented by the array expected.
The following operation can be performed on the tree any number of times:
- Pick a node
u
and flip its value. Also, flip the value of all the nodesv
in the subtree ofu
ifv % 2 = u % 2
. A nodev
lies in the subtree ofu
ifu
lies on the path fromv
toroot
. Flipping the value of a node means flipping its binary value, i.e., from0
to1
, and vice versa.
The tree is represented by the arrays tree_from[]
and tree_to[]
where tree_from[i]
is connected to tree_to[i]
via an edge for