


For the given ‘EDGES’ = [ [0,1],[1,2],[1,3],[1,4] ] and ‘N’ = 5.The number of nodes satisfying the condition is 1. Only Node 1 satisfies the given condition.

The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer, 'N’ denoting the number of nodes in the tree.
The next N-1 lines of each test case have two integers denoting an edge between them.
For each test case, print an integer corresponding to the number of nodes fulfilling the given condition.
Print the output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 5000.
0 <= Node Index in EDGES <= N-1.
Time limit: 1 sec
In this approach, we will create a ‘PARENT’ array to store the parent of each index and a ‘COUNT’ array to store the number of children of each node.
For each edge in ‘EDGES’, we will update the ‘COUNT’ and ‘PARENT’ array. After that, we will iterate over all nodes and check if ‘COUNT’[i] > COUNT[PARENT[i]] and increment our final answer accordingly.
In this approach, First, we will represent the tree into an adjacency list manner. TREE[i] will consist of all the indices of children of Node ‘i’. We will define a function DFS(‘CUR’, ’TREE’) that will recursively iterate over all the nodes of the tree and if the number of children of ‘CUR’ is greater than the number of children of its parent. We will increment our answer.