import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def dfs(cur, cost):
global visited
currentLocation = graph[cur]
currentType = currentLocation[0]
nextLocation = list(map(int, currentLocation[2:-1]))
if currentType == "L":
cost = max(cost, int(currentLocation[1]))
elif currentType == "T":
cost -= int(currentLocation[1])
if cost < 0: return False
if cur == n:
return True
visited.add(cur)
for nextLo in nextLocation:
if nextLo not in visited:
if dfs(nextLo, cost):
return True
visited.remove(cur)
return False
while True:
n = int(input())
if n == 0: break
graph = [()]
for i in range(n):
graph.append((input().rstrip().split()))
visited = set()
if (dfs(1, 0)):
print("Yes")
else:
print("No")
재귀도 다시 익혀야겠다 다까묵었넹
'코딩딩 > BOJ' 카테고리의 다른 글
[백준 9328 열쇠] 문제풀이 (0) | 2024.08.15 |
---|---|
[백준 16933 벽 부수고 이동하기 3] 문제풀이 (0) | 2024.08.14 |
[백준4485번 녹색 옷 입은 애가 젤다지?] 문제풀이 (0) | 2024.08.07 |
[백준11967번 불켜기] 문제풀이 (0) | 2024.08.06 |
[백준9205번 맥주 마시면서 걸어가기] 문제풀이 (0) | 2024.08.03 |