You're given a tree with n nodes numbered from 0 to n-1, rooted at node 0. The tree structure is defined by a 2D array edges where edges[i] = [ui, vi] represents an edge between nodes ui and vi.
Each node is painted with a color represented by the array colors, where colors[i] is the color of node i.
Your goal is to find the largest subtree where all nodes have the same color. A subtree rooted at node v includes node v and all its descendants.
Return the maximum number of nodes in such a monochromatic subtree.
Example: If we have a tree where node 2 and all its children have color 'red', and this subtree contains 5 nodes, while no other subtree has more than 5 nodes of the same color, then the answer is 5.
Input & Output
Constraints
- 1 โค n โค 105
- edges.length == n - 1
- 0 โค ui, vi < n
- 1 โค colors[i] โค 105
- The input represents a valid tree (connected and acyclic)