Complete Explanation + Readable Code
Intuition is every node that does not have the node withnums value of 1 in the subtree has ans= 1\nSo only the nodeas that have a node with nums value 1 in its 
Intuition is every node that does not have the node withnums value of 1 in the subtree has ans= 1\nSo only the nodeas that have a node with nums value 1 in its subtree will have some ans>1\nand so we find all the nodes that have nums value 1 in their subtree these nodes would be node(having num val 1) and its parent and then it\'s parent\'s parent until we hit the root\nso now to find ans of these nodes .\nwe use dfs to check which values are in a node\'s subtree and then for each such node traverse thorugh all the possible values of possible ans  and the smallest value which is not in the subtree is the ans for that node.\n\n```\n int bfs(int start,vector<vector<int>>&children,vector<int>&nums,vector<int>&done,int lastval)\n    {\n        queue<int>q;\n        q.push(start);\n        done[nums[start]]=1;\n        while(!q.empty())\n        {\n            // cout<<q.size()<<endl;\n            int x=q.front();\n            // cout<<x<<" child"<<endl;\n            q.pop();\n            \n            for(int i=0;i<children[x].size();i++)\n            {\n                if(done[nums[children[x][i]]]==0)\n                {\n                    done[nums[children[x][i]]]=1;\n                    q.push(children[x][i]);\n                }\n            }\n        }\n        for(int i=lastval;i<=pow(10,5)+1;i++)\n        {\n            if(done[i]==0)\n                return i;\n        }\n        return 1;\n    }\n    vector<int> smallestMissingValueSubtree(vector<int>& parent, vector<int>& nums) {\n        vector<vector<int>>children(parent.size());\n        int root,node;\n        for(int i=0;i<parent.size();i++)\n        {\n            if(parent[i]<0)\n                root=i;\n            else\n                children[parent[i]].push_back(i);\n        }\n        vector<int>nodes;\n        int e=1;\n        for(int i=0;i<nums.size();i++)\n        {\n            if(nums[i]==1)\n            {\n                node=i;\n                e=0;\n                nodes.push_back(node);\n                break;\n            }\n        }\n        vector<int>ans(nums.size(),1);\n        if(e==1)\n            return ans;\n        while(node!=root)\n        {\n            node=parent[node];\n            nodes.push_back(node);\n        }\n        \n        \n        int lastval=1;\n        vector<int>done(pow(10,5)+2);\n        \n        \n        for(int i=0;i<nodes.size();i++)\n        {\n            \n            lastval=bfs(nodes[i],children,nums,done,lastval);\n            ans[nodes[i]]=lastval;\n        }\n        return ans;\n    }\n```\n\nFeel free to ask any questions \nAnd please upvote if you liked my explanation
[]