Java Easy to understand
\nclass Solution {\n    public int[] smallestMissingValueSubtree(int[] parents, int[] nums) {\n        \n      ArrayList<ArrayList<Integer>> adj=new ArrayList<>
```\nclass Solution {\n    public int[] smallestMissingValueSubtree(int[] parents, int[] nums) {\n        \n      ArrayList<ArrayList<Integer>> adj=new ArrayList<>();\n        int n=parents.length;\n        int res[]=new int[n];\n        Arrays.fill(res,1);\n      for(int i=0;i<n;i++)\n      {\n          adj.add(new ArrayList<Integer>());\n      }\n        \n        for(int i=1;i<n;i++)\n        {\n            adj.get(parents[i]).add(i);\n        }\n        \n        int indOne=-1;\n        for(int i=0;i<n;i++)\n        {\n            if(nums[i]==1)\n            {\n                indOne=i;\n                break;\n            }\n        }\n        \n        if(indOne==-1)\n            return res;\n        \n        boolean vis[]=new boolean[n+2];\n        int mex=1;\n        while(indOne!=-1)\n        {\n            dfs(adj,indOne,vis,nums);\n            \n            while(vis[mex])\n            {\n                mex++;\n            }\n            \n            res[indOne]=mex;\n            indOne=parents[indOne];\n            \n            \n        }\n        return res;\n    }\n    \n    public void dfs(ArrayList<ArrayList<Integer>> adj,int i,boolean vis[],int nums[])\n    {\n        if(vis[nums[i]])\n            return ;\n        \n        vis[nums[i]]=true;\n        \n        for(int j:adj.get(i))\n        {\n            dfs(adj,j,vis,nums);\n        }\n        \n    }\n}\n```
['Depth-First Search', 'Java']