노트

[백준] 5567번 결혼식 python 본문

알고리즘

[백준] 5567번 결혼식 python

_Myway 2023. 7. 30. 15:05
from collections import deque

def bfs(node):
    queue = deque()
    queue.append(node)
    while queue:
        node = queue.popleft()
        for n in friend[node]:
            if check[n] == 0:
                check[n] = check[node]+1
                queue.append(n)

n = int(input())
m = int(input())
friend = [[] for _ in range(n+1)]

for j in range(m):
    a,b=map(int,input().split(' '))
    friend[a].append(b)
    friend[b].append(a)
check = [0]*(n+1)
check[1] = 1
bfs(1)
res = sum([1 for t in check if 2 <= t <= 3])
print(res)
Comments