✅ JAVA EASY | COMMENTED CODE
\nclass Solution {\n    public int[] smallestMissingValueSubtree(int[] parent, int[] nums) {\n        HashMap<Integer,ArrayList<Integer>> map = new HashMap<>();
```\nclass Solution {\n    public int[] smallestMissingValueSubtree(int[] parent, int[] nums) {\n        HashMap<Integer,ArrayList<Integer>> map = new HashMap<>();\n        int n = nums.length;\n        int[] ans = new int[n];\n        \n        //if suppose 1 is missing then 1 will be the smallest value missing from all\n        Arrays.fill(ans , 1);\n        \n        //now look for one in nums val as all are distinct and for which node it is keep it in one var\n        int one = -1;\n        for(int i = 0; i < n; i++){\n            if(nums[i] == 1){\n                one = i;\n                break;\n            }\n        }\n        \n        //if one is not there in whole tree then that is the ans for everyone\n        if(one == -1)\n            return ans;\n        \n        //for ith node check parent and add the ith node as children\n        for(int i = 0; i < n; i++){\n            map.computeIfAbsent(parent[i], x -> new ArrayList<>()).add(i);\n        }\n        \n        boolean[] visited = new boolean[n + 2];//as if all till n present then smallest will be n + 1\n        //and numbers start  from 0 so n + 2\n        \n        int min = 1;\n        while(one != -1){\n            DFS(map, one, visited, nums);\n            //all subtree\'s will be marked now look for the smallest val available\n            \n            while(visited[min]){\n                min++;\n            }\n            \n            ans[one] = min;//this will be ans for you my boy \n            one = parent[one];//now shift with your parent\n        }\n        return ans;\n    }\n    \n    \n    private void DFS(HashMap<Integer,ArrayList<Integer>> map, int node, boolean[] visited, int[] val){\n        //if this node is already marked or used then leave it as it\'s subtree will also be marked\n        if(visited[val[node]])\n            return;\n        \n        visited[val[node]] = true;\n        for(int nbr : map.getOrDefault(node, new ArrayList<>())){\n            DFS(map, nbr, visited, val);//go and mark your childrens\n        }\n    }\n}\n```
['Depth-First Search', 'Java']