Setu | OA | Tree Enigma (Solution Needed)
744

Tree comprising N nodes, rooted at node 1.

Every node has a value 0 or 1. Initial values are provided in arr []
Some values are corrupted. Correct values in brr []

Two operations permitted:

  • Invert value of i'th node. i.e change 0 to 1 or vice versa
  • Invert values of all nodes in subtree of i'th node (including i)

Find minimum number of operations to change values to correct ones.

Sample Input

Input Format:

  • N -> number of nodes
  • u, v -> denotes there is an edge between u & v (n-1 such lines)
  • a1 a2 .. an -> arr (inital values) each value 0 or 1
  • b1 b2 .. bn -> brr (correct values) each value 0 or 1

Example:

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

Expected Output: 2
Explanation: Invert nodes 2 & 4


Comments (2)