You are given the following:
A path is called special path if the following conditions are satisfied:
Task:
Count the no. of special paths in the tree. (Two paths are different if they contain at least one different node.)
Example:
N = 5
edges = [(1,2), (1,3), (3,4), (3,5)]
A = [2,3,1,2,3]

Output:
2
Explanation:
path 1: 1(2)->3(1)->4(2)
path 2: 2(3)->1(2)->3(1)->5(3)
Constraints
1<= T <= 10
2 <= N <= 10^5
1<=Ai <= 10^9
I tried brute force by applying DFS at every node. I got TLE.
Any suggestions or approach is appreciated :)