Golang
\nfunc componentValue(nums []int, edges [][]int) int {\n    sum := 0\n    for _, v := range nums {\n        sum += v\n    }\n    \n    g := make([][]int, len(nu
```\nfunc componentValue(nums []int, edges [][]int) int {\n    sum := 0\n    for _, v := range nums {\n        sum += v\n    }\n    \n    g := make([][]int, len(nums))\n    for _, e := range edges {\n        g[e[0]] = append(g[e[0]], e[1])\n        g[e[1]] = append(g[e[1]], e[0])\n    }\n    \n    res := 0\n    for i := 1; i < sum; i++ {\n        if sum % i == 0 {\n            res = max(res, search(g, nums, i))\n        }\n    }\n    return res\n}\n\nfunc max(a int,b int) int {\n    if a > b {\n        return a\n    }\n    return b\n}\n\nfunc search(g [][]int, nums []int, tar int) int {\n    fmt.Println(tar)\n    nums2 := make([]int, len(nums))\n    copy(nums2, nums)\n    \n    degree := make([]int, len(nums))\n    for i := 0; i < len(nums); i++ {\n        degree[i] = len(g[i])\n    }\n    \n    var queue []int\n    for i, d := range degree {\n        if d == 1 {\n            queue = append(queue, i)\n        }\n    }\n    \n    res := 0\n    for len(queue) > 0 {\n        l := len(queue)\n        for i := 0; i < l; i++ {\n            a := queue[i]\n            if nums2[a] > tar {\n                return 0\n            }\n            if degree[a] != 1 {\n                continue\n            }\n            for _, v := range g[a] {\n                if degree[v] != 0 {\n                    degree[v]--\n                    degree[a]--\n                    \n                    if nums2[a] < tar {\n                        nums2[v] += nums2[a]\n                    } else {\n                        res++\n                    }\n                    if degree[v] == 1 {\n                        queue = append(queue, v)\n                    }\n                }\n            }\n            \n        }\n        queue = queue[l:]\n    }\n    return res\n}\n```
[]