C++  dfs
\nclass Solution {\n    void dfs(int x, const vector<int>&nums, const vector<vector<int>> &con, vector<int> &p, vector<int> &start, vector<int> &end, int& t) {\
```\nclass Solution {\n    void dfs(int x, const vector<int>&nums, const vector<vector<int>> &con, vector<int> &p, vector<int> &start, vector<int> &end, int& t) {\n        start[x] = t++;\n        if (nums[x] < p.size()) {\n            p[nums[x]] = x;\n        }\n        for (int y : con[x]) {\n            dfs(y, nums, con, p, start, end, t);\n        }\n        end[x] = t++;\n        \n    }\npublic:\n    vector<int> smallestMissingValueSubtree(vector<int>& parents, vector<int>& nums) {\n        const int n = nums.size();\n        vector<vector<int>> con(n);\n        for (int i = 1; i < n; ++i) {\n            con[parents[i]].push_back(i);\n        }\n        vector<int> p(n + 2, -1), start(n), end(n);\n        int t = 0;\n        dfs(0, nums, con, p, start, end, t);\n        vector<int> r(n, 1);\n        for (int i = 2, f = p[1]; i < p.size() && f >= 0; ++i) {\n            while (f >= 0 && (p[i] < 0 || start[f] > start[p[i]] || end[f] < end[p[i]])) {\n                r[f] = i;\n                f = parents[f];\n            }            \n        }\n        return r;\n    }\n};\n\n```
[]