Skip to content

Commit ba5c64a

Browse files
authored
#21 : 2606_바이러스_DFS
#21 : Week5_예원이티
1 parent dbfc98d commit ba5c64a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#DFS
2+
3+
computer=int(input())
4+
v=int(input())
5+
6+
graph = [[] for i in range(computer+1)]
7+
visited=[0]*(computer+1)
8+
9+
for i in range(v):
10+
a,b=map(int,input().split())
11+
graph[a]+=[b]
12+
graph[b]+=[a]
13+
14+
def dfs(v):
15+
visited[v]=1
16+
for nx in graph[v]:
17+
if visited[nx]==0:
18+
dfs(nx)
19+
20+
dfs(1)
21+
print(sum(visited)-1)

0 commit comments

Comments
 (0)