일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 백준
- NAV
- ubuntu
- 13237
- MongoDB
- baekjun
- algotythm
- 트리
- 라즈베리파이
- 2579
- 2909
- dp
- CSS
- node.js
- 라즈베리파이3b+
- springboot3.x
- 파이썬
- Algorythm
- bootstrap
- nav-tab
- Python
- dynaminprogramming
- 알고리즘
- 16.04
- 라즈비안
- 라즈베리파이3
- Crawling
- HTML
- raspberrypi
- 크롤링
Archives
- Today
- Total
노트
[백준] 5567번 결혼식 python 본문
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)
'알고리즘' 카테고리의 다른 글
[백준] 1197번 최소 스패닝 트리 python (0) | 2023.08.20 |
---|---|
[백준] 2775번 부녀회장이 될테야 python (0) | 2023.08.13 |
[백준] 2002번 추월 python (0) | 2023.07.23 |
[백준] 4949번 균형잡힌 세상 python (0) | 2023.07.11 |
[백준] 2606번 바이러스 python (0) | 2023.07.09 |
Comments