We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 63b3581 commit 0ac6205Copy full SHA for 0ac6205
Python_BOJ_2023/24444.py
@@ -0,0 +1,34 @@
1
+# BFS
2
+from collections import deque
3
+import sys
4
+
5
+input = lambda: sys.stdin.readline().rstrip()
6
+n, m, r = map(int, input().split())
7
+graph = [[] for _ in range(n + 1)]
8
9
+for _ in range(m):
10
+ u, v = map(int, input().split())
11
+ graph[u].append(v)
12
+ graph[v].append(u)
13
+visited = [0] * (n + 1)
14
+cnt = 1
15
16
+def bfs():
17
+ global cnt
18
+ queue = deque()
19
+ queue.append((r))
20
+ visited[r] = 1
21
22
+ while queue:
23
+ now_node = queue.popleft()
24
+ graph[now_node].sort()
25
+ for next_node in graph[now_node]:
26
+ if not visited[next_node]:
27
+ cnt += 1
28
+ visited[next_node] = cnt
29
+ queue.append((next_node))
30
31
+bfs()
32
33
+for val in visited[1:]:
34
+ print(val)
0 commit comments