Skip to content

Commit 4bb6843

Browse files
author
hangyeol
committed
123차 1차 문제풀이
1 parent 45c8eeb commit 4bb6843

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sys
2+
3+
def main():
4+
input = sys.stdin.readline
5+
G = int(input())
6+
P = int(input())
7+
8+
parent = [i for i in range(G+1)]
9+
10+
def find(x):
11+
if parent[x] != x:
12+
parent[x] = find(parent[x])
13+
return parent[x]
14+
15+
count = 0
16+
17+
for _ in range(P):
18+
g = int(input())
19+
dockingGate = find(g)
20+
21+
if dockingGate == 0:
22+
break
23+
parent[dockingGate] = find(dockingGate - 1)
24+
count += 1
25+
26+
print(count)
27+
28+
if __name__ == '__main__':
29+
main()

0 commit comments

Comments
 (0)