import collections
from collections import deque
n,m,v = map(int,input().split())
graph = collections.defaultdict(list)
for i in range(m):
a,b = map(int,input().split())
graph[a] += [b]
graph[a].sort()
graph[b] += [a]
graph[b].sort()
def dsf_recursive(node, visited):
visited.append(node)
for adj in graph[node]:
if adj not in visited:
dsf_recursive(adj, visited)
return visited
def bsf_queue(start):
visited = [start]
q = deque([start])
while q:
node = q.popleft()
for adj in graph[node]:
if adj not in visited:
q.append(adj)
visited.append(adj)
return visited
for i in dsf_recursive(v, []):
print(i, end=" ")
print()
for i in bsf_queue(v):
print(i, end=" ")
어찌저찌 풀긴했는데,,
너무 코드가 이상한 것 같다..
뭐랄까.. 말로 표현할 수 없는.. 그 애매함..
강의에서 들은 DFS, BFS 구현을 듣지 않았더라면 풀지도 못했을 텐데
겨우.. 풀었다..
킹치만? 마음에 안든다