五月天青色头像情侣网名,国产亚洲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講]的評論 (共 條)

分享到微博請遵守國家法律
扎囊县| 贡山| 涿鹿县| 玛曲县| 霍邱县| 新丰县| 汝州市| 德令哈市| 嘉黎县| 上饶市| 海安县| 临颍县| 柯坪县| 惠州市| 曲麻莱县| 平度市| 公主岭市| 颍上县| 建宁县| 公主岭市| 临猗县| 和顺县| 罗城| 昭平县| 来凤县| 伊川县| 吉安县| 交口县| 商洛市| 宜良县| 抚松县| 应城市| 温州市| 龙山县| 龙泉市| 新建县| 景洪市| 裕民县| 利津县| 屯门区| 水城县|