Java Solution
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    // n = 5
    // nums = [6,2,2,2,6]
    // graph = [[1], [0,2,3], [1], [1,4], [3]]
    // sum = 18
    // k = 5 -> 4 -> 3
    // 18%5 != 0 -> continue
    // 18%4 != 0 -> continue
    // 18%3 == 0 -> ans = helper(graph, 0, -1, 6, nums)
    // helperSum = 6
    public int componentValue(int[] nums, int[][] edges) {
        int n = nums.length;
        List<Integer>[] adjList = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            adjList[i] = new ArrayList<>();
        }
        for (int[] edge: edges) {
            adjList[edge[0]].add(edge[1]);
            adjList[edge[1]].add(edge[0]);
        }
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum = sum + nums[i];
        }

        for (int k = n; k > 0; k--) {
            if (sum % k != 0) {
                continue;
            }
            int ans = helper(adjList, 0, -1, sum / k, nums);
            if (ans == 0) {
                return k - 1;
            }
        }

        return 0;
    }

    public int helper(List<Integer>[] adjList, int index, int prev, int target, int[] nums) {
        if (adjList[index].size() == 1 && adjList[index].get(0) == prev) {
            if(nums[index] > target) {
                return -1;
            }
            if (nums[index] == target) {
                return 0;
            }
            return nums[index];
        }

        int helperSum = nums[index];
        for (int k: adjList[index]) {
            if (k == prev) {
                continue;
            }
            int ans = helper(adjList, k, index, target, nums);
            if (ans == -1) {
                return -1;
            }
            helperSum = helperSum + ans;
        }

        if (helperSum > target) {
            return -1;
        }
        if (helperSum == target) {
            return 0;
        }

        return helperSum;
    }
}
```
['Java']