C++ solution
\n\nclass Solution {\npublic:\n    vector<int> smallestMissingValueSubtree(vector<int>& parents, vector<int>& nums) {\n        auto tree = getTree(parents);\n  
```\n\nclass Solution {\npublic:\n    vector<int> smallestMissingValueSubtree(vector<int>& parents, vector<int>& nums) {\n        auto tree = getTree(parents);\n        vector<int> res(parents.size(), 1);\n        \n        auto oneNode = find(nums.begin(), nums.end(), 1) - nums.begin();\n        if (oneNode == nums.size()) {\n            return res;\n        }\n        \n        unordered_set<int> seen;\n        int missing = 1;\n        \n        while (oneNode != -1) {\n            dfs(tree, seen, nums, oneNode);\n\n            while (seen.count(missing)) {\n                ++missing;\n            }\n            \n            res[oneNode] = missing;\n            oneNode = parents[oneNode];\n        }\n        \n        return res;\n    }\n    \nprivate:\n    vector<vector<int>> getTree(const vector<int>& parents) {\n        vector<vector<int>> tree(parents.size());\n        for (int node = 0; node < parents.size(); ++node) {\n            if (parents[node] != -1) {\n                tree[parents[node]].push_back(node);\n            }\n        }\n        \n        return tree;\n    }\n    \n    void dfs(const vector<vector<int>>& tree, unordered_set<int>& seen, const vector<int>& nums, int node) {\n        if (seen.count(nums[node])) {\n            return;\n        }\n        seen.insert(nums[node]);\n        for (auto child: tree[node]) {\n            dfs(tree, seen, nums, child);\n        }\n    }\n};\n\n```
[]