[Python3] dfs
Please check out this commit for solutions of weekly 258. \n\nclass Solution:\n    def smallestMissingValueSubtree(self, parents: List[int], nums: List[int]) ->
Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/0de189059bd6af4dabe23d9066dde1655f3334fc) for solutions of weekly 258. \n```\nclass Solution:\n    def smallestMissingValueSubtree(self, parents: List[int], nums: List[int]) -> List[int]:\n        ans = [1] * len(parents)\n        if 1 in nums: \n            tree = {}\n            for i, x in enumerate(parents): \n                tree.setdefault(x, []).append(i)\n                \n            k = nums.index(1)\n            val = 1\n            seen = set()\n            \n            while k != -1: \n                stack = [k]\n                while stack: \n                    x = stack.pop()\n                    seen.add(nums[x])\n                    for xx in tree.get(x, []): \n                        if nums[xx] not in seen: \n                            stack.append(xx)\n                            seen.add(nums[xx])\n                while val in seen: val += 1\n                ans[k] = val\n                k = parents[k]\n        return ans \n```
['Python3']