O(N) cpp solution || Easy to understand
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\nvector<int> taken;\nint ptr;\nvector<int> res;\nvector<int> n;\nint time;\nvector<vector<int>> tree;\nint help(int node){\n    taken[n[node]]=time++;\n    int temp=1;\n    for(int i=0;i<tree[node].size();i++)\n        temp=max(temp,help(tree[node][i]));\n    \n        while(temp<taken.size() && taken[temp]>=taken[n[node]])temp++;\n    \n    res[node]=temp;\n    return temp;\n    \n    \n}\n\n    vector<int> smallestMissingValueSubtree(vector<int>& parents, vector<int>& nums) {\n        tree=vector<vector<int>> (parents.size(),vector<int>(0,0));\n        for(int i=1;i<parents.size();i++)\n            tree[parents[i]].push_back(i);\n        taken=vector<int>(1e5+2,-1);\n        ptr=1;\n        n=nums;\n        time=0;\n        res=vector<int>(parents.size(),0);\n        help(0);\n        return res;\n        \n    }\n};\n```
['C++']