Easy Java Solution
```\nclass Solution {\n    int[] nums;\n    public int componentValue(int[] nums, int[][] edges) {\n        int n = nums.length;\n        this.nums = nums;\n   
```\nclass Solution {\n    int[] nums;\n    public int componentValue(int[] nums, int[][] edges) {\n        int n = nums.length;\n        this.nums = nums;\n        List<Integer>[] graph = new ArrayList[n];\n        for(int i=0; i<n; i++) {\n            graph[i] = new ArrayList<>();\n        }\n        for(int[] e : edges) {\n            graph[e[0]].add(e[1]);\n            graph[e[1]].add(e[0]);\n        }\n        \n        int sum = 0;\n        for(int i : nums) {\n            sum += i;\n        }\n        \n        for(int k=n; k>0; k--) {\n            if(sum % k != 0) continue;\n            int ans = helper(graph, 0, -1, sum / k);\n            if(ans == 0) return k-1;\n        }\n        return 0;\n    }\n    \n    private int helper(List<Integer>[] graph, int i, int prev, int target) {\n        if(graph[i].size() == 1 && graph[i].get(0) == prev) {\n            if(nums[i] > target) return -1;\n            if(nums[i] == target) return 0;\n            return nums[i];\n        }\n        \n        int sum = nums[i];\n        for(int k : graph[i]) {\n            if(k == prev) continue;\n            int ans = helper(graph, k, i, target);\n            if(ans == -1) return -1;\n            sum += ans;\n        }\n        \n        if(sum > target) return -1;\n        if(sum == target) return 0;\n        return sum;\n    }\n}
['Java']