dfs_prn = []
def dfs(graph, v, ch):
global dfs_prn
dfs_prn.append(v)
if ch[v] == False:
ch[v] = True
for i in graph[v]:
if not ch[i]:
dfs(graph, i, ch)
N, M, V = map(int,input().split())
ch = [False] * (N+1)
graph = [[]*(N+1) for _ in range(N+1)]
for i in range(M):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
graph[a].sort()
graph[b].sort()
dfs(graph, V, ch)
for x in dfs_prn:
print(x, end=' ')
'파이썬 - 자료구조' 카테고리의 다른 글
[ 파이썬 자료구조 ] 파이썬-재귀함수 (0) | 2023.08.18 |
---|---|
[파이썬 - 자료구조] 우선순위 큐 (0) | 2023.07.29 |
[파이썬 - 자료구조] deque 이란 (0) | 2023.07.25 |
[파이썬-자료구조] 스택의 개념 (0) | 2023.07.21 |