You are given a rooted tree with N vertices numbered from 0 to N - 1, rooted at vertex 0.
For every vertex i (1 ≤ i < N), you are given its parent parent[i]. Each edge from parent[i] to i is labeled with a lowercase English letter label[i]. (The root has no incoming edge.)
A path is considered valid if the multiset of characters on its edges can be rearranged to form a palindrome.
Your task is to determine the number of unordered pairs of vertices (u, v) (u < v) such that the unique simple path between u and v is valid.
S is a string of length N, where S[0] is ignored and S[i] is the label of the edge (parent[i], i).
Print a single integer — the number of valid pairs.
Expert in Data Structures & Algorithms. Building tools to help developers crack FAANG interviews.