Check all factors greedily
\nfrom collections import *\n\nclass Solution:\n    def maxsplits(self, graph, i, prev, k, values):\n        res = 0\n        curr = values[i]\n        res = 0\
```\nfrom collections import *\n\nclass Solution:\n    def maxsplits(self, graph, i, prev, k, values):\n        res = 0\n        curr = values[i]\n        res = 0\n        for j in graph[i]:\n            if j != prev:\n                ncurr, nres = self.maxsplits(graph, j, i, k, values)\n                curr += ncurr\n                res += nres\n        if curr == k:\n            res += 1\n            curr = 0\n        return curr, res\n    \n    def componentValue(self, nums: List[int], edges: List[List[int]]) -> int:\n        graph = defaultdict(set)\n        for a, b in edges:\n            graph[a].add(b)\n            graph[b].add(a)\n        res = 0\n        total = sum(nums)\n        s = 1\n        while s * s <= total:\n            if total % s == 0:\n                x = self.maxsplits(graph, 0, -1, s, nums)\n                if x[0] == 0:\n                    res = max(res, x[1] - 1)\n                if s * s < total:\n                    x = self.maxsplits(graph, 0, -1, total // s, nums)\n                    if x[0] == 0:\n                        res = max(res, x[1] - 1)\n            s += 1\n \xA0 \xA0 \xA0 \xA0return res \n```
[]