You are a geneticist studying a family tree represented as a tree data structure. The tree consists of n individuals numbered 0 to n - 1, where person 0 is the common ancestor (root).
Each person in the family carries a unique genetic marker - an integer value between 1 and 105. Your task is to analyze each person's "genetic lineage" (their subtree) and find the smallest positive genetic value that doesn't exist in their family line.
Input:
parents: Array whereparents[i]is the parent of personi(withparents[0] = -1for root)nums: Array wherenums[i]is the genetic value of personi
Goal: Return an array where each element represents the smallest missing genetic value in that person's subtree (including themselves and all descendants).
A subtree rooted at node x contains node x and all nodes that can be reached by following parent-child relationships downward from x.
Input & Output
Constraints
- n == parents.length == nums.length
- 1 โค n โค 105
- parents[0] == -1
- For i โ 0, 0 โค parents[i] โค n - 1
- parents represents a valid tree
- 1 โค nums[i] โค 105
- All values in nums are distinct