c++ || Graph || dfs || set
\nclass Solution {\npublic:\n    //to find all which all is included\n    void dfs(vector<vector<int>>&graph,vector<bool>&visited,int curr,set<int>&s1,vector<in
```\nclass Solution {\npublic:\n    //to find all which all is included\n    void dfs(vector<vector<int>>&graph,vector<bool>&visited,int curr,set<int>&s1,vector<int>&num){\n        if(visited[curr]) return;\n        visited[curr]=true;\n        for(auto child:graph[curr]){\n            if(!visited[child]) dfs(graph,visited,child,s1,num);\n        }\n        //erasing value from set so tha min value is always at the top\n        s1.erase(num[curr]);\n    }\n    vector<int> smallestMissingValueSubtree(vector<int>& parents, vector<int>& nums) {\n        int n=nums.size();\n        vector<int>ans(n,1);\n        int temp=-1;\n        //to check if 1 is present in nums or not if not present then return ans with all 1;\n        for(int i=0;i<nums.size();i++){\n            if(nums[i]==1){\n                temp=i;\n                break;\n            }\n        }\n        if(temp==-1) return ans;\n        //now start maiking directed graph\n        vector<vector<int>>vect(n);\n        for(int i=1;i<parents.size();i++){\n            vect[parents[i]].push_back(i);\n        }\n        //visited array because we donot want to visit a subtree when we go till root from node whose nums[i] is 1\n        vector<bool>visited(n+10,false);\n        //to store min till now\n        set<int>s1;\n        for(int i=0;i<=n;i++) s1.insert(i+1);\n        //storing all the parents of node[i] whose nums[i] value is 1;\n        vector<int>tobevisited;\n        while(temp!=-1){\n            tobevisited.push_back(temp);\n            temp=parents[temp];\n        }\n        //now only for parents of nums[i]=1 to be visited and all node must have value =1 in ans \n        for(int i=0;i<tobevisited.size();i++){\n            dfs(vect,visited,tobevisited[i],s1,nums);\n            ans[tobevisited[i]]=*s1.begin();\n        }\n        return ans;\n        \n    }\n};\n```
[]