Given a tree with colored nodes, determine the number of distinct perfect route cycles that can be formed by adding an edge between two nodes of different colors.
Example 1:
Input:[6,[1,2,2,1,5],[2,3,4,5,6],[0,1,1,1,0,0]]
Output:3
Constraints:
1 ≤ tree_nodes ≤ 10^5
1 ≤ m < 10^5
0 ≤ colors[i] < 1
Loading...
Run code to see test results
00:00 / 69:42
Count Route Cycles
HardMed•781 views
Given a tree with colored nodes, determine the number of distinct perfect route cycles that can be formed by adding an edge between two nodes of different colors.