We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b0cb552 commit 79f8d37Copy full SHA for 79f8d37
1 file changed
이티준희/2606_바이러스.py
@@ -0,0 +1,37 @@
1
+#2023-05-11-Week5-과제
2
+#2606_바이러스
3
+
4
+'''
5
+입력
6
7
+7 총 컴퓨터 수
8
+6 컴퓨터 간 연결된 선 개수
9
+1 2 1번컴퓨터와 2번컴퓨터 연결
10
+2 3
11
+...
12
+4 7
13
14
15
+#bfs 너비 우선 탐색
16
+import sys
17
+from collections import deque
18
+vertex = int(sys.stdin.readline()) # 컴퓨터 개수
19
+edge = int(sys.stdin.readline()) # 연결선 개수
20
21
+graph = [[NULL] for i in range(vertex+1)] #그래프
22
+visited = [0]*(vertex+1) #1번 인덱스부터 사용
23
24
+for i in range(edge): # 그래프 생성
25
+ a,b = map(int,stdin.split())
26
+ graph[a]+=[b] # a 에 b 연결
27
+ graph[b]+=[a] # b 에 a 연결
28
29
+visited[1] = 1 # 1번 컴퓨터부터 시작이니 방문 표시
30
+queue = deque([1])
31
+while queue :
32
+ result = queue.popleft()
33
+ for i in graph[result]:
34
+ if visited[i]==0:
35
+ queue.append(i)
36
+ visited[i]=1
37
+print(sum(visited)-1)
0 commit comments