Skip to content

Commit d3a6a43

Browse files
committed
Update
1 parent 7879324 commit d3a6a43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+279
-279
lines changed

10/1.cpp

Whitespace-only changes.

10/1.java

Whitespace-only changes.

10/2.cpp

Whitespace-only changes.

10/2.java

Whitespace-only changes.

10/2.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +0,0 @@
1-
# 특정 원소가 속한 집합을 찾기
2-
def find_parent(parent, x):
3-
# 루트 노드가 아니라면, 루트 노드를 찾을 때까지 재귀적으로 호출
4-
if parent[x] != x:
5-
parent[x] = find_parent(parent, parent[x])
6-
return parent[x]
7-
8-
# 두 원소가 속한 집합을 합치기
9-
def union_parent(parent, a, b):
10-
a = find_parent(parent, a)
11-
b = find_parent(parent, b)
12-
if a < b:
13-
parent[b] = a
14-
else:
15-
parent[a] = b
16-
17-
# 노드의 개수와 간선(Union 연산)의 개수 입력 받기
18-
v, e = map(int, input().split())
19-
parent = [0] * (v + 1) # 부모 테이블 초기화하기
20-
21-
# 부모 테이블상에서, 부모를 자기 자신으로 초기화
22-
for i in range(1, v + 1):
23-
parent[i] = i
24-
25-
# Union 연산을 각각 수행
26-
for i in range(e):
27-
a, b = map(int, input().split())
28-
union_parent(parent, a, b)
29-
30-
# 각 원소가 속한 집합 출력하기
31-
print('각 원소가 속한 집합: ', end='')
32-
for i in range(1, v + 1):
33-
print(find_parent(parent, i), end=' ')
34-
35-
print()
36-
37-
# 부모 테이블 내용 출력하기
38-
print('부모 테이블: ', end='')
39-
for i in range(1, v + 1):
40-
print(parent[i], end=' ')

10/3.cpp

Whitespace-only changes.

10/3.java

Whitespace-only changes.

10/3.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ def union_parent(parent, a, b):
2222
for i in range(1, v + 1):
2323
parent[i] = i
2424

25-
cycle = False # 사이클 발생 여부
26-
25+
# Union 연산을 각각 수행
2726
for i in range(e):
2827
a, b = map(int, input().split())
29-
# 사이클이 발생한 경우 종료
30-
if find_parent(parent, a) == find_parent(parent, b):
31-
cycle = True
32-
break
33-
# 사이클이 발생하지 않았다면 합치기(Union) 수행
34-
else:
35-
union_parent(parent, a, b)
28+
union_parent(parent, a, b)
29+
30+
# 각 원소가 속한 집합 출력하기
31+
print('각 원소가 속한 집합: ', end='')
32+
for i in range(1, v + 1):
33+
print(find_parent(parent, i), end=' ')
34+
35+
print()
3636

37-
if cycle:
38-
print("사이클이 발생했습니다.")
39-
else:
40-
print("사이클이 발생하지 않았습니다.")
37+
# 부모 테이블 내용 출력하기
38+
print('부모 테이블: ', end='')
39+
for i in range(1, v + 1):
40+
print(parent[i], end=' ')

10/4.cpp

Whitespace-only changes.

10/4.java

Whitespace-only changes.

0 commit comments

Comments
 (0)