五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

【算法】并查集(Disjoint Set)[共3講]

2023-07-13 16:08 作者:wechannnnnn  | 我要投稿

Golang版本代碼

package main

import "fmt"

const VERTICES = 6

func initialise(parent []int) {

for i := 0; i < VERTICES; i++ {

parent[i] = -1

}

}

func find_root(x int, parent []int) int {

x_root := x

for parent[x_root] != -1 {

x_root = parent[x_root]

}

return x_root

}

func union_vertices(x, y int, parent, rank []int) int {

x_root := find_root(x, parent)

y_root := find_root(y, parent)

if x_root == y_root {

return 0

} else {

if rank[x_root] > rank[y_root] {

parent[y_root] = x_root

} else if rank[y_root] > rank[x_root] {

parent[x_root] = y_root

} else {

parent[x_root] = y_root

rank[y_root]++

}

}

return 1

}

func main() {

parent := make([]int, VERTICES, VERTICES)

rank := make([]int, VERTICES, VERTICES)

edges := [][]int{

{0, 1}, {1, 2}, {1, 3},

{3, 4}, {2, 5},

}

initialise(parent)

for _, edge := range edges {

x := edge[0]

y := edge[1]

if union_vertices(x, y, parent, rank) == 0 {

fmt.Println("Cycle detected!")

return

}

}

fmt.Println("No cycles found.")

}

【算法】并查集(Disjoint Set)[共3講]的評論 (共 條)

分享到微博請遵守國家法律
娱乐| 衡东县| 凤阳县| 天台县| 鄄城县| 阳新县| 玛纳斯县| 临澧县| 白水县| 台北市| 澳门| 通江县| 广昌县| 蓬安县| 常德市| 张掖市| 济阳县| 松阳县| 蒙城县| 穆棱市| 锡林浩特市| 呼图壁县| 夏邑县| 德化县| 鹤峰县| 上杭县| 宁蒗| 永城市| 鸡东县| 大关县| 浑源县| 株洲县| 张家港市| 库车县| 佳木斯市| 百色市| 赤壁市| 张家界市| 潞城市| 东丽区| 呼伦贝尔市|