Intuitive understandable code || java 
IntuitionIn this problem, we want to split a tree into multiple connected components such that each component has the same sum of node values. To do this, we fi
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
In this problem, we want to split a tree into multiple connected components such that each component has the same sum of node values. To do this, we first calculate the total sum of all the node values. We then check all possible ways to divide this sum by trying different divisors, which represent the target sum for each component. For each divisor, we use Depth-First Search (DFS) to explore if it's possible to split the tree into parts where each part's sum matches the target value. If we find a valid way to split, we count how many edges we can remove to create these components. The goal is to maximize the number of edges we can remove while still forming components with equal sums.

You can check for reference the question [https://leetcode.com/problems/maximum-number-of-k-divisible-components/description/?envType=daily-question&envId=2024-12-21](2872). Its very similar to this question. 

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