Created
November 9, 2019 12:21
-
-
Save inspirit941/9815969fbeb74619c305d5dc89cb4fd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| g = int(sys.stdin.readline()) | |
| p = int(sys.stdin.readline()) | |
| plane = [] | |
| for _ in range(p): | |
| plane.append(int(sys.stdin.readline())) | |
| def parent_find(x): | |
| if x == parent[x]: | |
| return x | |
| p = parent_find(parent[x]) | |
| parent[x] = p | |
| return parent[x] | |
| def union(x, y): | |
| x = parent_find(x) | |
| y = parent_find(y) | |
| parent[x] = y | |
| # parent[0] = 0 까지 만들어준다. parent[x] = 0까지 만들어지는 게 핵심 | |
| parent = {i:i for i in range(g+1)} | |
| cnt = 0 | |
| for i in plane: | |
| x = parent_find(i) | |
| if x == 0: | |
| break | |
| union(x, x-1) | |
| cnt += 1 | |
| print(cnt) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment