JavaScript || Beats 100%
Code\n\nvar componentValue = function(nums, edges) {\n    var dfs = function(nums, g, cur, parent, target) {\n        var curSum = nums[cur];\n        for (var 
# Code\n```\nvar componentValue = function(nums, edges) {\n    var dfs = function(nums, g, cur, parent, target) {\n        var curSum = nums[cur];\n        for (var i = 0; i < g[cur].length; i++) {\n            var nbr = g[cur][i];\n            if (nbr === parent) continue;\n            curSum += dfs(nums, g, nbr, cur, target);\n        }\n        \n        if (curSum === target) {\n            return 0;\n        } else {\n            return curSum;\n        }\n    };\n    \n    var n = nums.length;\n    var g = new Array(n);\n    for (var i = 0; i < n; i++) {\n        g[i] = [];\n    }\n    \n    for (var i = 0; i < edges.length; i++) {\n        var e = edges[i];\n        g[e[0]].push(e[1]);\n        g[e[1]].push(e[0]);\n    }\n    \n    var sum = 0;\n    for (var i = 0; i < nums.length; i++) {\n        sum += nums[i];\n    }\n    \n    var st = {};\n    for (var i = 0; i < nums.length; i++) {\n        st[nums[i]] = true;\n    }\n    var numDistinctValues = Object.keys(st).length;\n    \n    if (numDistinctValues === 1) {\n        return n - 1;\n    }\n    \n    for (var i = n - 1; i >= 2; i--) {\n        if (sum % i !== 0) continue;\n        \n        var ans = dfs(nums, g, 0, -1, sum / i);\n        \n        if (ans === 0) return i - 1;\n    }\n    \n    return 0;\n};\n\n\n\n```
['JavaScript']