C++ | BFS
\nclass Solution {\npublic:\n    vector<int> smallestMissingValueSubtree(vector<int>& parent, vector<int>& nums) \n    {\n        int n=parent.size();\n        
```\nclass Solution {\npublic:\n    vector<int> smallestMissingValueSubtree(vector<int>& parent, vector<int>& nums) \n    {\n        int n=parent.size();\n        vector<vector<int>>adj(n);\n        for(int i=1;i<n;i++)\n            adj[parent[i]].push_back(i);\n        int start=-1;\n        for(int i=0;i<n;i++)\n        {\n            if(nums[i]==1)\n            {\n                start=i;\n                break;\n            }\n        }\n        vector<int>res(n,1);\n        if(start==-1)\n            return res;\n        vector<bool>vis(100005,false);   // Visited for value\n        vector<bool>node(n,false);       // Visited for tree node\n        int curr_min=1;\n        while(start!=-1)\n        {\n            queue<int>q;\n            q.push(start);\n            while(!q.empty())\n            {\n                int u=q.front();\n                q.pop();\n                vis[nums[u]]=true;\n                node[u]=true;\n                for(auto v:adj[u])\n                {\n                    if(!node[v])\n                        q.push(v);\n                }\n            }\n            while(vis[curr_min])\n                curr_min++;\n            res[start]=curr_min;\n            start=parent[start];\n        }\n        return res;\n    }\n};\n```
[]