Turn Off The Tree

Company: Experian_1july

Difficulty: medium

Problem Statement

Turn Off The Tree Problem Description You are given a tree with N nodes, labelled 1 to N , and M edges. Every node carries a state: the state of node i is State[i - 1] , and it is either 0 or 1 . When you click a node, the states of that node and of every node directly connected to it by an edge are reversed: each 0 becomes 1 , and each 1 becomes 0 . Find the minimum number of clicks needed to make the state of every node in the tree equal to 0 . If no sequence of clicks can do this, the answer is -1 . Function Description Complete the function getMin , which has the following parameters: N : INTEGER - the number of nodes in the tree. M : INTEGER - the number of edges in the tree. M is always N - 1 . col : INTEGER - the number of columns of A . col is always 2 . A : INTEGER 2D ARRAY of size M x col - the edges of the tree; there is an edge between A[i][0] and A[i][1] . State : INTEGER ARRAY of length N - State[i] is the starting state of node i + 1 . The function returns an INTEGER: th