go union find

chacha·2020년 7월 24일
0

go알고리즘

목록 보기
6/8

source

func merge(a int, b int) {
	a = find(a)
	b = find(b)
	if a == b {
		return
	}
	root[b] = a
}

func find(n int) int {
	if root[n] < 0 {
		return n
	}
	root[n] = find(root[n])
	return root[n]
}
profile
안녕하세요~ :)

0개의 댓글