dfs on path
\nclass Solution {\npublic:\n    void dfs(int now,int par,vector<int> &ans,vector<int> &a,set<int> &s,vector<vector<int>> &v,vector<bool> &vis)\n    {\n        
```\nclass Solution {\npublic:\n    void dfs(int now,int par,vector<int> &ans,vector<int> &a,set<int> &s,vector<vector<int>> &v,vector<bool> &vis)\n    {\n        vis[now]=1;\n        s.erase(a[now]);\n        for(auto to:v[now])\n            if(to!=par && !vis[to])\n                dfs(to,now,ans,a,s,v,vis);\n    }\n    \n    vector<int> smallestMissingValueSubtree(vector<int>& p, vector<int>& a) \n    {\n        vector<vector<int>> v(p.size()+5);\n        for(int i=1;i<p.size();i++)\n            v[p[i]].push_back(i);\n        \n        set<int> s;\n        for(int i=1;i<p.size()+2;i++)\n            s.insert(i);\n        vector<int> ans(p.size(),1);\n        int start=-1;\n        for(int i=0;i<a.size();i++)\n            if(a[i]==1)\n                start=i;\n        \n        vector<bool> vis(p.size()+2,0);\n        while(start!=-1)\n        {\n            dfs(start,p[start],ans,a,s,v,vis);\n            ans[start]=*s.begin();\n            start=p[start];\n        }\n        return ans;\n    }\n};\n```
['Depth-First Search', 'C', 'C++']