
Input: ‘N’ = 3 and edges are [{1, 2, 0, 5}, {2, 3, 1, 3}] and edges are given in format {u, v, type, weight}.
Output: 3
Explanation: There is only one GOOD pair, i.e. {2, 3} and the weight of the edge is 3.
The first line of input contains an integer ‘T’, denoting the number of test cases.
The first line of each test case contains the integer ‘N’.
The next ‘N’ - 1 line contains four integers ‘A’, ‘B’, TYPE’ and ‘VAL’ where ‘A’ and ‘B’ represents the vertices of the tree, ‘TYPE’ represent the type of the edge and ‘VAL’ define the edge weight.
For each test case, print an integer denoting the sum of the weight of all the paths of all the GOOD pairs.
Print the output of each test case in a new line.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 5
1 <= ‘N’ <= 10^5
1 <= ‘U’, ‘V’ <= ‘N’
0 <= ‘VAL’ <= 10^3
It is guaranteed that the input graph forms a tree.
Time Limit: 1 sec
Algorithm :
Algorithm :
Algorithm :
dfs(graph, index, visited, subtree, size, allAcceptedEdges):