We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dbfc98d commit ba5c64aCopy full SHA for ba5c64a
1 file changed
이티예원/2606_바이러스_DFS.py
@@ -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