본문 바로가기
코딩테스트 파이썬/백준

뱀과 사다리 게임

by 세용용용용 2024. 11. 26.

16928번: 뱀과 사다리 게임

 

나의 풀이

from collections import deque
import sys
input = sys.stdin.readline

q, w = map(int, input().rstrip().split())
map_list = [i for i in range(1, 101)]
visit = [False]*100
for _ in range(q+w):
    e, r = map(int, input().rstrip().split())
    map_list[e-1] = r

queue = deque([(1,0)])
visit[0] = True
while queue:
    now_pt, now_ct = queue.popleft()
    
    if (now_pt == 100):
        print(now_ct)
        break
    
    for move in range(1, 7):
        next_pt = now_pt + move
        if (next_pt <= 100) and (visit[next_pt - 1] == False):
            visit[next_pt - 1] = True
            queue.append((map_list[next_pt-1], now_ct + 1))

'코딩테스트 파이썬 > 백준' 카테고리의 다른 글

단어 나누기  (1) 2024.12.04
막대기  (1) 2024.12.03
적록색약  (0) 2024.11.25
토마토 (7576)  (0) 2024.11.22
토마토 (7569)  (0) 2024.11.22