https://www.acmicpc.net/problem/13549
import sys
from collections import deque
input = sys.stdin.readline
start, end = map(int, input().split())
graph = [-1 for _ in range(100001)]
graph[start] = 0
queue = deque()
queue.append(start)
while queue:
target = queue.popleft()
if target == end:
print(graph[target])
break
a, b, c = target-1, target+1, target*2
if 0 <= a < 100001 and graph[a] == -1:
graph[a] = graph[target] + 1
queue.append(a)
if 0 <= c < 100001 and graph[c] == -1:
graph[c] = graph[target]
queue.appendleft(c)
if 0 <= b < 100001 and graph[b] == -1:
graph[b] = graph[target] + 1
queue.append(b)
BFS를 이용해서 풀면 된다.