Problem solving
백준 5014번 스타트링크 (Python 3)
storkbear
2022. 8. 30. 17:40
Baekjoon online judge 5014번 파이썬
링크
https://www.acmicpc.net/problem/5014
5014번: 스타트링크
첫째 줄에 F, S, G, U, D가 주어진다. (1 ≤ S, G ≤ F ≤ 1000000, 0 ≤ U, D ≤ 1000000) 건물은 1층부터 시작하고, 가장 높은 층은 F층이다.
www.acmicpc.net
소스코드
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
def bfs(start):
queue=deque()
queue.append([start,0])
index=[u,-d]
visited=set()
visited.add(start)
while queue:
node,cnt=queue.popleft()
if node==g:
print(cnt)
return
for i in index:
new_node=node+i
if 1<=new_node<=f and new_node not in visited:
visited.add(new_node)
queue.append([new_node,cnt+1])
print('use the stairs')
return
f,s,g,u,d=map(int,input().split())
bfs(s)