C++|| LCA based
\n\tvector tin(100001),tout(100001);\nclass Solution {\npublic:\n\n    int timer=0;\n    bool helper(int a, int b)\n    {\n        return ((tin[a]>=tin[b]) && (
\n\tvector<int> tin(100001),tout(100001);\nclass Solution {\npublic:\n\n    int timer=0;\n    bool helper(int a, int b)\n    {\n        return ((tin[a]>=tin[b]) && (tout[a]<=tout[b]));\n    }\n    void dfs(int root, vector<int> balak[],vector<int> &nums)\n    {\n        tin[nums[root]]= ++timer;\n        for(auto child : balak[root])\n            dfs(child,balak,nums);\n        \n        tout[nums[root]]= ++timer;\n    }\n    \n    void dfss(int root, vector<int> balak[], vector<int> &out, vector<int> &nums)\n    {\n        int maxo = -1;\n        for(auto child : balak[root])\n        {\n            dfss(child,balak,out,nums);\n            maxo=max(maxo,out[child]);\n        }\n        \n        if(maxo==-1) // leaf\n        {\n            if(nums[root]!=1)\n                out[root]=1;\n            else\n                out[root]=2;\n        }\n        else\n        {\n            int st = maxo;\n            while(st<100001)\n            {\n                if(helper(st,nums[root])==false)\n                break;\n                st++;\n            }\n            out[root]=st;\n        }\n        return ;\n    }\n    \n    vector<int> smallestMissingValueSubtree(vector<int>& parents, vector<int>& nums) {\n        int n = nums.size();\n        vector<int> out(n,1e6);\n        \n        vector<int> balak[n+1];\n        for(int i=1; i<parents.size(); i++)\n            balak[parents[i]].push_back(i);\n        \n        for(int i=0; i<100001; i++)\n        {\n            tin[i]=0;\n            tout[i]=0;\n        }\n        dfs(0,balak,nums);\n        dfss(0,balak,out,nums);\n        \n        return out;\n    }\n};
['C', 'C++']