-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16928.py
30 lines (29 loc) · 837 Bytes
/
16928.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sys
from collections import deque
input=lambda:sys.stdin.readline().rstrip()
def bfs():
graph=[0]*101
dq=deque([1])
dx=[1,2,3,4,5,6]
while dq:
x=dq.popleft()
if x==100:
break
for i in dx:
dn=x+i
if 1<dn<=100 and graph[dn]==0:
graph[dn]=graph[x]+1
for j in shortcut:
if dn==j[0]:
dn=j[1]
if graph[dn]==0:
graph[dn]=graph[x]+1
dq.append(dn)
break
else:
dq.append(dn)
print(graph[100])
shortcut=[]
for _ in range(sum(map(int,input().split()))):
shortcut.append(tuple(map(int,input().split())))
bfs()