[Python] Union Find + DFS
\nclass UF:\n    def __init__(self, n):\n        self.parents = list(range(n + 1))\n    \n    def find(self, u):\n        if self.parents[u] != u:\n            
```\nclass UF:\n    def __init__(self, n):\n        self.parents = list(range(n + 1))\n    \n    def find(self, u):\n        if self.parents[u] != u:\n            self.parents[u] = self.find(self.parents[u])\n        return self.parents[u]\n        \n    def union(self, u, v):\n        p, q = self.find(u), self.find(v)\n        if p == q: return 0\n        self.parents[p] = q\n        return q\n    \nclass Solution:\n    def smallestMissingValueSubtree(self, parents: List[int], nums: List[int]) -> List[int]:\n        def dfs(tree):\n            smallest = max({dfs(subTree) for subTree in graph[tree]} | {1})\n            for subTree in graph[tree]:\n                uf.union(nums[tree], nums[subTree])\n                \n            for i in range(smallest, n + 1):\n                if uf.find(i) != uf.find(nums[tree]):\n                    res[tree] = i\n                    return i\n            else: return i + 1\n            \n        n, graph = len(nums), defaultdict(list)\n        uf, res = UF(100000), [1] * n\n        for i, p in enumerate(parents):\n            graph[p].append(i)\n\n        res[0] = dfs(0)\n        return res\n```
['Depth-First Search', 'Union Find', 'Python']