[Silver III]
https://www.acmicpc.net/problem/2606
풀이
2차원 배열을 통해 네트워크(그래프)를 생성하고, BFS를 돌려 1번 컴퓨터와 연결된 컴퓨터의 개수를 센다.
from collections import deque
computers = []
visited = []
ans = 0
def solve(cur):
global ans
global visited
global computers
q = deque()
q.append(cur)
visited[cur] = True
while q:
cur = q.popleft()
for i in computers[cur]:
if not visited[i]:
q.append(i)
visited[i] = True
ans += 1
# main
n = int(input())
m = int(input())
for i in range(n + 1):
computers.append([])
visited.append(False)
for i in range(m):
a, b = map(int, input().split())
computers[a].append(b)
computers[b].append(a)
solve(1)
print(ans)