python 3    ||     dfs, some explanation    ||     T/S: 53% / 30%
\nclass Solution:\n    def componentValue(self, nums: List[int], edges: List[List[int]]) -> int:\n\n        def dfs(a, b):                      # if this subtre
```\nclass Solution:\n    def componentValue(self, nums: List[int], edges: List[List[int]]) -> int:\n\n        def dfs(a, b):                      # if this subtree has sum value of div, make it zero\n        \n            tally = nums[a]\n            for c in graph[a]: \n                if c != b:\n                    tally += dfs(c, a)\n            \n            return tally if tally != div else 0\n        \n        graph = defaultdict(list)\n        n, sm, mx, mn = len(nums), sum(nums), max(nums), min(nums)\n\n        for a, b in edges:                  # build the graph\n            graph[a].append(b)\n            graph[b].append(a)\n        \n        for div in range(mx, sm//mn):       # consider each potential divisor of sm\n            if not(sm%div or dfs(0, n-1)):  # if divisor and whole tree has sum-value of zero, success\n                return sm//div-1            # number of deletions is one less than number of components\n\n        return 0                             # no successes\n```\n[https://leetcode.com/submissions/detail/826733562/](https://leetcode.com/submissions/detail/826733562/)\n\nI could be wrong, but I think that time complexity is *O*(*N* ^2) and space complexity is *O*(*N*), in which *N* ~ `len(nums)` and *N* ~ `len(nums)`.
['Python']