Golang | BFS
Golang implementation of https://leetcode.com/problems/create-components-with-same-value/discuss/2706736/Python-Explanation-with-pictures-BFS\n\nfunc componentV
- Golang implementation of https://leetcode.com/problems/create-components-with-same-value/discuss/2706736/Python-Explanation-with-pictures-BFS\n```\nfunc componentValue(nums []int, edges [][]int) int {\n    maxNum, minNum, sumNums, n := 0, math.MaxInt32, 0, len(nums)\n    for _, num := range nums {\n        maxNum = max(maxNum, num)\n        minNum = min(minNum, num)\n        sumNums += num\n    }\n    G := make(map[int]map[int]struct{})\n    degree := make([]int, n)\n    for _, edge := range edges {\n        a, b := edge[0], edge[1]\n        degree[a]++\n        degree[b]++\n        if _, ok := G[a]; !ok {\n            G[a] = make(map[int]struct{})\n        }\n        G[a][b] = struct{}{}\n        if _, ok := G[b]; !ok {\n            G[b] = make(map[int]struct{})\n        }\n        G[b][a] = struct{}{}\n    }\n    \n    for i := minNum; i < sumNums; i++ {\n        if sumNums % i == 0 && bfs(i, nums, degree, G) {\n            return (sumNums / i) - 1\n        }\n    }\n    return 0\n}\n\nfunc bfs(target int, nums []int, degree []int, G map[int]map[int]struct{}) bool {\n    V := make([]int, len(nums))\n    copy(V, nums)\n    deg := make([]int, len(degree))\n    copy(deg, degree)\n    \n    q := make([]int, 0)\n    for i, d := range degree {\n        if d == 1 {\n            q = append(q, i)\n        }\n    }\n    \n    for len(q) > 0 {\n        i := q[0]\n        q = q[1:]\n        deg[i] = 0\n        \n        for nxt, _ := range G[i] {\n            if V[i] != target {\n                V[nxt] += V[i]\n            }\n            deg[nxt]--\n            if deg[nxt] == 0 {\n                return V[nxt] == target\n            } else if deg[nxt] == 1 {\n                q = append(q, nxt)\n            }\n        }\n    }\n    return false\n}\n\nfunc max(x, y int) int {\n    if x > y {\n        return x\n    }\n    return y\n}\n\nfunc min(x, y int) int {\n    if x < y {\n        return x\n    }\n    return y\n}\n```
['Go']