BOJ - 10775 - 공항

Updated:

import sys

def find(x):
    if(parent[x] == x): return x

    parent[x] = find(parent[x])
    return parent[x]

def union(x, y):
    rootX = find(x)
    rootY = find(y)
    parent[rootX] = rootY

if __name__ == "__main__":
    G = int(input())
    P = int(input())
    parent = [i for i in range(G + 1)]
    plane = []
    for _ in range(P):
        plane.append(int(sys.stdin.readline()))

    count = 0
    for i in range(P):
        check = find(plane[i])
        if check == 0:
            break
        union(check, check-1)
        count += 1

    print(count)

https://www.acmicpc.net/problem/10775

Categories:

Updated:

Leave a comment