If for example, we have pairs that are similar, where .
Complete the similarPair function in the editor below. It should return an integer that represents the number of pairs meeting the criteria.
similarPair has the following parameter(s):
n: an integer that represents the number of nodes
k: an integer
edges: a two dimensional array where each element consists of two integers that represent connected node numbers
The first line contains two space-separated integers and , the number of nodes and the similarity threshold.
Each of the next lines contains two space-separated integers defining an edge connecting nodes and , where node is the parent to node .
Print a single integer denoting the number of similar pairs in the tree.
The similar pairs are , , , and , so we print as our answer.
Observe that and are not similar pairs because they do not satisfy for .