Skip to content

Commit 06dc7ba

Browse files
committed
[Gold V] Title: 뱀과 사다리 게임, Time: 116 ms, Memory: 110068 KB -BaekjoonHub
1 parent d303ae4 commit 06dc7ba

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

백준/Gold/16928. 뱀과 사다리 게임/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
### 제출 일자
1414

15-
2025년 3월 24일 12:39:47
15+
2025년 3월 24일 12:46:55
1616

1717
### 문제 설명
1818

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
from collections import deque
22

33
N, M = map(int, input().split())
4-
adj = {i: i for i in range(1, 101)} # 기본적으로 자기 자신을 가리키도록 초기화
4+
adj = {i: i for i in range(1, 101)}
55

6-
for _ in range(N + M):
6+
for _ in range(N+M):
77
x, y = map(int, input().split())
8-
adj[x] = y # 사다리와 뱀 적용
8+
adj[x] = y
99

10-
q = deque([(1, 0)]) # 1번 칸에서 시작
10+
q = deque([(1, 0)])
1111
visited = [False] * 101
12-
visited[1] = True # 시작 지점 방문 처리
13-
12+
visited[1] = True
1413
while q:
1514
pos, step = q.popleft()
1615

17-
if pos == 100: # 100번 칸 도착하면 종료
16+
if pos == 100:
1817
print(step)
1918
break
2019

21-
for i in range(1, 7): # 주사위 1~6까지 던지기
22-
next_pos = pos + i
23-
if next_pos > 100:
20+
for i in range(1, 7):
21+
next = pos + i
22+
if next > 100:
2423
continue
2524

26-
next_pos = adj[next_pos] # 사다리나 뱀 적용
25+
next = adj[next]
2726

28-
if not visited[next_pos]: # 방문하지 않은 경우만 이동
29-
visited[next_pos] = True
30-
q.append((next_pos, step + 1))
27+
if not visited[next]:
28+
visited[next] = True
29+
q.append((next, step+1))

0 commit comments

Comments
 (0)