본문 바로가기
카테고리 없음

서로소 집합 알고리즘

by rosemarie 2023. 2. 24.
반응형

경로 압축: find 함수를 재귀적으로 호출한 뒤에 부모 테이블 값을 갱신하는 기법

<경로 압축 기법 소스코드

def find_parent(parent, x):
	if parent[x]!=x:
     	parent[x]=find_parent(parent, parent[x])
    return parent[x]

>