위상정렬 + 구현
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')
'practivceAlgorithm > 백준' 카테고리의 다른 글
[백준][Python] 1913 달팽이 (0) | 2021.08.16 |
---|---|
[백준][Python] 16139 컴퓨터 인간 상호작용 (0) | 2021.08.16 |
[백준][Python] 16206 롤케이크 (0) | 2021.08.16 |
[백준][Python] 1305 광고 (0) | 2021.08.16 |
[백준][Python] 16988 바둑2 (0) | 2021.08.16 |