Skip to content

Commit 60158cd

Browse files
authored
Update 3.py
1 parent 8c89847 commit 60158cd

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

10/3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def union_parent(parent, a, b):
1616

1717
# 노드의 개수와 간선(Union 연산)의 개수 입력 받기
1818
v, e = map(int, input().split())
19-
parent = {}
19+
parent = [0] * (v + 1) # 부모 테이블 초기화하기
2020

2121
# 부모 테이블상에서, 부모를 자기 자신으로 초기화
2222
for i in range(1, v + 1):
@@ -30,6 +30,7 @@ def union_parent(parent, a, b):
3030
if find_parent(parent, a) == find_parent(parent, b):
3131
cycle = True
3232
break
33+
# 사이클이 발생하지 않았다면 합치기(Union) 수행
3334
else:
3435
union_parent(parent, a, b)
3536

0 commit comments

Comments
 (0)