Python solution
Solution: find  the total sum of node vals. if our tree can be split, the sum of each subtree must equal one divisor of the total sum. check if we can split the
Solution: find  the total sum of node vals. if our tree can be split, the sum of each subtree must equal one divisor of the total sum. check if we can split the tree for every divisor of the total sum. To save time:\n\n1.  skip divisors smaller than the largest node val\n2. check divisors from low to high. We terminate after finding the first divisor that can split the tree, which leads to the max edge removals\n\n\nHow many divisors we may check in the worst case? For a num N, the common approximate upper bound of # of divisors is N^1/3. \nthe exact bounds for the number of divisors of any n-digit number are (http://oeis.org/A066150):   4, 12, 32, 64, 128, 240, 448, 768, 1344\n\n    nums = [1,5,5,4,11]\n    edges = [[0,1],[1,2],[1,3],[3,4]]\n\n    tree=collections.defaultdict(set)\n    for i,j in edges:\n         tree[i].add(j)\n         tree[j].add(i)\n  \n    def check(cur,prev,target):\n        val=nums[cur]\n        for kid in tree[cur]-{prev}:\n           i=check(kid,cur,target)\n           if i==-1: return -1\n           val+=i          \n        return val%target if val<=target else -1\n    \n    tot=sum(nums)\n    for n in range(min(tot//max(nums),len(nums)),0,-1):  # for simplicity, i do not use O(n^1/2) approach to find all factors here\n        if not tot%n and check(0,-1,tot//n)==0:\n           return n-1
['Python']