얼렁뚱땅 백준 문제풀이
[백준 문제풀이] 얼렁뚱땅 2644번 촌수계산 풀이
MOSTAR
2022. 4. 19. 19:59
import sys
from collections import deque
point = int(sys.stdin.readline())
n, m = map(int, sys.stdin.readline().split())
edge = int(sys.stdin.readline())
array_= [[] for i in range(point+1)]
visited = [False] * (point+1)
for i in range(edge) :
a, b = map(int,sys.stdin.readline().split())
array_[a].append(b)
array_[b].append(a)
q = deque()
q.append((m,0))
check = 0
while q :
this,count = q.popleft()
visited[this] = True
if this==n :
check = 1
print(count)
break
for i in array_[this] :
if visited[i] == False :
q.append((i,count+1))
if check == 0 :
print(-1)
어라리.. 어라리.. 내가 어케풀었지..
근데 예전엔 골드 풀어볼려고 발악하다 스트레스 받았는데
이젠 실버만푼다 ..^^ .......................................................................................... 거참 정신건강은 괜찮네