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 aa28a76 commit 17f4dc5Copy full SHA for 17f4dc5
Python_BOJ_2023/2606.py
@@ -0,0 +1,26 @@
1
+# 바이러스
2
+import sys
3
+input = lambda: sys.stdin.readline()
4
+
5
+n = int(input())
6
+m = int(input())
7
+graph = [[] for _ in range(n + 1)]
8
+for _ in range(m):
9
+ x, y = map(int, input().split())
10
+ graph[x].append(y)
11
+ graph[y].append(x)
12
13
+ans = 0
14
+visited = [0] * (n + 1)
15
16
+def dfs(node):
17
+ global ans
18
+ visited[node] = 1
19
+ graph[node].sort()
20
+ for next_node in graph[node]:
21
+ if not visited[next_node]:
22
+ dfs(next_node)
23
+ ans += 1
24
25
+dfs(1)
26
+print(ans)
0 commit comments