You are given a tree (a connected, undirected graph with no cycles) rooted at node 0, consisting of n nodes numbered from 0 to n - 1. The tree structure is represented by a 0-indexed array parent of size n, where parent[i] is the parent of node i. Since node 0 is the root, parent[0] == -1.
Additionally, you have a string s of length n, where s[i] represents the character assigned to node i.
Your goal: Find the longest path in the tree such that no two adjacent nodes on the path have the same character. The path can start and end at any nodes in the tree.
Note: A path is a sequence of nodes where each adjacent pair is connected by an edge. The length of a path is the number of nodes in it.
Input & Output
Constraints
- n == parent.length == s.length
- 1 โค n โค 105
- 0 โค parent[i] โค n - 1 for all i โฅ 1
- parent[0] == -1
- parent represents a valid tree
- s consists of only lowercase English letters