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 0ac6205 commit f4739aaCopy full SHA for f4739aa
Python_BOJ_2023/24479.py
@@ -0,0 +1,28 @@
1
+# DFS
2
+import sys
3
+
4
+input = lambda: sys.stdin.readline().rstrip()
5
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
14
+cnt = 1
15
+visited = [0] * (n + 1)
16
+visited[r] = 1
17
18
+def dfs(now):
19
+ global cnt
20
+ graph[now].sort()
21
+ for next in graph[now]:
22
+ if not visited[next]:
23
+ cnt += 1
24
+ visited[next] = cnt
25
+ dfs(next)
26
27
+dfs(r)
28
+print(visited)
0 commit comments