


Ninja found an old book that has a given tree of numbers. Ninja is interested to find the number of members of that tree that has more children than its parent.
There are ‘N’ nodes in the tree and each node is indexed with a number between 0 to ‘N’-1. The tree is given in a form of an ‘EDGES’ array. Each element of ‘EDGES’ has two values, denoting an edge between that two nodes. The root of the tree is Node 0. Your task is to find the number of nodes having more children than their parent’s node.
For ExampleFor 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.
Output Format:
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.
Note:
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
2
5
0 1
1 2
1 3
1 4
3
0 1
0 2
1
0
For the first test case,
The number of nodes satisfying the condition is 1.
Only Node 1 satisfies the given condition as no of children of Node 1 is 3 and no of children of its parent (Node 0) is 1. Hence the answer is 1.

For the second test case:
There are no nodes that fulfill the given condition.
Hence the answer is 0.
2
6
0 1
1 2
1 3
1 4
2 5
6
0 1
0 2
1 3
1 4
1 5
1
1
Try to store the children’s count of each node.
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.
Algorithm:
O(N), where ‘N’ is the number of nodes in the given tree.
In this approach, we are iterating over all edges to fill the ‘PARENTS’ and ‘COUNT’ arrays and there are only N-1 edges and so iterated over all the nodes to calculate the answer. Hence the overall time complexity is O(N).
O(N), where ‘N’ is the number of nodes in the given tree.
In this approach, we are using ‘PARENTS’ and ‘COUNT’ arrays which are of size N. Hence the overall space complexity is O(N).