practivceAlgorithm/백준

[백준][Python] 14676 영우는 사기꾼

findTheValue 2021. 8. 16. 00:57

위상정렬 + 구현

level있는 빌딩을 지을수는 없지만

building이 있는데 레벨이 있을 수도 있음(하위건물이 파괴되어)

import sys
input = sys.stdin.readline

N, M, K = map(int,input().split())
graph = {i: [] for i in range(1,N+1)}
level = {i: 0 for i in range(1,N+1)}
built = {i:0 for i in range(1,N+1)}
for _ in range(M):
    a, b = map(int, input().split())
    graph[a] += [b]
    level[b] += 1

for _ in range(K):
    command, building = map(int, input().split())
    if command==1:
        if not level[building]:
            built[building] += 1
            if built[building]==1:
                for next in graph[building]:
                    level[next] -= 1
        else:
            print('Lier!')
            exit()
    else:
        if built[building] >=1:
            built[building] -= 1
            if not built[building]:
                for next in graph[building]:
                    level[next] += 1
        else:
            print('Lier!')
            exit()

print('King-God-Emperor')