C++ Solution | Euler tour
\nconst int N=100005;\nclass Solution {\npublic:\n    map<int,int> mp,rmp;\n    vector<int> g[N],ans,st,ed;int n,tm;\n    void dfs(int node,int par){\n        s
```\nconst int N=100005;\nclass Solution {\npublic:\n    map<int,int> mp,rmp;\n    vector<int> g[N],ans,st,ed;int n,tm;\n    void dfs(int node,int par){\n        st[node]=tm++;\n        for(int j:g[node]){\n            if(j!=par) dfs(j,node);\n        }\n        ed[node]=tm++;\n    }\n    vector<int> smallestMissingValueSubtree(vector<int>& p, vector<int>& a) {\n        mp.clear();rmp.clear();\n        int n=a.size();tm=0;\n        ans.clear();ans.resize(n,1);\n        st.clear();st.resize(n,1);\n        ed.clear();ed.resize(n,1);\n        for(int i=0;i<n;i++) g[i].clear();\n        for(int i=1;i<n;i++){\n            g[i].push_back(p[i]);\n            g[p[i]].push_back(i);\n        }\n        for(int i=0;i<n;i++){\n            mp[a[i]]=i;\n            rmp[i]=a[i];\n        }\n        dfs(0,0);\n        if(!mp.count(1)) return ans;\n        int cv=2,cur=mp[1];\n        while(cur!=-1){\n            while(1){\n                if(!mp.count(cv)) break;\n                int cc=mp[cv];\n                if(st[cc]>=st[cur] && ed[cc]<=ed[cur]) cv++;\n                else break;\n            }\n            ans[cur]=cv;\n            cur=p[cur];\n        }\n        return ans;\n    }\n};\n```
[]