DFS math solution [EXPLAINED]
IntuitionSplit the tree into parts where the sum of node values in each part is the same. We do this by exploring all ways to divide the total sum of node value
# Intuition
Split the tree into parts where the sum of node values in each part is the same. We do this by exploring all ways to divide the total sum of node values evenly, using the tree structure to check if such a division is possible.

# Approach
Traverse the tree using DFS and calculate subtree sums while checking if they can match a target sum, using an adjacency list for efficient neighbor lookups.

# Complexity
- Time complexity:
O(n . divisors of total_sum),since DFS runs O(n) for each divisor of the total sum.

- Space complexity:
O(n), for the adjacency list and recursive call stack.

# Code
```python3 []
class Solution:
    def componentValue(self, nums, edges):
        from collections import defaultdict

        # Create an adjacency list for the tree
        graph = defaultdict(list)
        for a, b in edges:
            graph[a].append(b)
            graph[b].append(a)

        total_sum = sum(nums)

        def is_valid(target):
            """Check if it's possible to partition the tree into components with the target sum."""
            visited = [False] * len(nums)

            def dfs(node):
                visited[node] = True
                current_sum = nums[node]

                for neighbor in graph[node]:
                    if not visited[neighbor]:
                        subtree_sum = dfs(neighbor)
                        if subtree_sum == -1:
                            return -1
                        current_sum += subtree_sum

                if current_sum > target:
                    return -1
                return current_sum if current_sum < target else 0

            for i in range(len(nums)):
                if not visited[i]:
                    if dfs(i) == -1:
                        return False
            return True

        # Find the maximum number of deletable edges
        for k in range(total_sum, 0, -1):
            if total_sum % k == 0:
                target = total_sum // k
                if is_valid(target):
                    return k - 1

        return 0

```
['Array', 'Math', 'Tree', 'Depth-First Search', 'Enumeration', 'Python3']