Java Solution
The idea is to find out the node whose genetic value is 1 and traverse up . All the rest of the subtrees have one missing.\n\n\nclass Solution {\n    HashMap<In
The idea is to find out the node whose genetic value is 1 and traverse up . All the rest of the subtrees have one missing.\n\n```\nclass Solution {\n    HashMap<Integer,Set<Integer>> tree = new HashMap<>();\n    TreeSet<Integer> absent = new TreeSet<>();\n    int [] ans;\n    public int[] smallestMissingValueSubtree(int[] parents, int[] nums) {\n        int geneticNode = -1;\n        for(int i=0;i<parents.length;i++){\n            absent.add(i+1);\n            int parent = parents[i];\n            Set<Integer> set = tree.getOrDefault(parent,new HashSet<>());\n            set.add(i);\n            tree.put(parent,set);\n            if(nums[i]==1){\n                geneticNode = i;\n            }\n        }\n        ans = new int[parents.length];\n        if(geneticNode == -1){\n            Arrays.fill(ans,1);\n            return ans;\n        }\n        Arrays.fill(ans,-1);\n        dfs(geneticNode,-1,nums);\n        ans[geneticNode] = absent.isEmpty()?parents.length+1:absent.first();\n        int parent = parents[geneticNode];\n        parentDfs(parent,geneticNode,nums,parents);\n        for(int i=0;i<ans.length;i++){\n            if(ans[i] == -1){\n                ans[i] = 1;\n            }\n        }\n        return ans;\n    }\n    \n    private void parentDfs(int node,int nodeToIgnore,int [] nums,int []parents){\n        if(node == -1){\n            return;\n        }\n        for(int child : tree.getOrDefault(node,new HashSet<>())){\n            if(child!=nodeToIgnore){\n                dfs(child,node,nums);\n            }\n        }\n        absent.remove(nums[node]);\n        ans[node] = absent.isEmpty()?parents.length+1:absent.first();\n        parentDfs(parents[node],node,nums,parents);\n    }\n    \n    private void dfs(int node ,int parent,int[] nums){\n        absent.remove(nums[node]);\n        for(int child : tree.getOrDefault(node,new HashSet<>())){\n            if(parent != child){\n                dfs(child,node,nums);\n            }\n        }\n    }\n}\n```
[]