Easy java DFS
\n# Code\n\nclass Solution {\n    public int componentValue(int[] nums, int[][] edges) {\n        Map<Integer, Set<Integer>> graph = new HashMap();\n        int
\n# Code\n```\nclass Solution {\n    public int componentValue(int[] nums, int[][] edges) {\n        Map<Integer, Set<Integer>> graph = new HashMap();\n        int sum = 0;\n        int maxValue = 0;\n        for(int index = 0; index < nums.length; index += 1) {\n            sum += nums[index];\n            maxValue = Math.max(maxValue, nums[index]);\n        }\n        for(int index = 0; index < edges.length; index += 1) {\n            int u = edges[index][0];\n            int v = edges[index][1];\n            Set<Integer> children1 = graph.getOrDefault(u, new HashSet());\n            children1.add(v);\n            graph.put(u, children1);\n\n            Set<Integer> children2 = graph.getOrDefault(v, new HashSet());\n            children2.add(u);\n            graph.put(v, children2);\n        }\n        int ans = 0;\n        int n = nums.length;\n        int maxCount = sum / maxValue;\n        for(int index = maxCount; index > 1 ; index -= 1) {\n            if(sum % index == 0) {\n                boolean[] visited = new boolean[n];\n                int ans2 = isPossible(graph, sum/index, 0, nums, visited);\n                if(ans2 == 0) {\n                    return (index - 1);\n                }\n            }\n        }\n        return ans;\n    }\n    private int isPossible(Map<Integer, Set<Integer>> graph, int targetSum, int start, int[] nums, boolean[] visited) {\n        \n        if(nums[start] > targetSum) return nums[start];\n        visited[start] = true;\n        Set<Integer> children = graph.getOrDefault(start, new HashSet());\n        int childSum = nums[start];\n        for(Integer child: children) {\n            if(!visited[child]) {\n                int tempAns = isPossible(graph, targetSum, child, nums, visited);\n                childSum += tempAns;\n            }\n        }        \n        if(childSum == targetSum) {\n            return 0;\n        }\n        return childSum;\n    }\n\n}\n```
['Java']