Skip to content

Commit 17f4dc5

Browse files
committed
[23.01.09/Python] 바이러스
1 parent aa28a76 commit 17f4dc5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Python_BOJ_2023/2606.py

+26
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)