DFS py3
\n# Code\n\nclass Solution:\n    def smallestMissingValueSubtree(self, parents: List[int], nums: List[int]) -> List[int]:\n        n = len(parents)\n        res
\n# Code\n```\nclass Solution:\n    def smallestMissingValueSubtree(self, parents: List[int], nums: List[int]) -> List[int]:\n        n = len(parents)\n        res= [1]*n\n        if 1 not in set(nums):\n            return res\n        seen = set([])\n        graph = {i:set([]) for i in range(n)}\n        for i,p in enumerate(parents):\n            if p >= 0:\n                graph[p].add(i)\n        def dfs(node):\n            seen.add(nums[node])\n            for child in graph[node]:\n                if nums[child] not in seen:\n                    seen.add(nums[child])\n                    dfs(child)\n        \n        i = nums.index(1)\n        t = 1\n        while i!=-1:\n            dfs(i)\n            while t in seen:\n                t += 1\n            res[i] = t\n            i = parents[i]\n        return res\n\n\n```
['Depth-First Search', 'Python3']