diff --git "a/H0ngJu/BFS/\353\243\250\353\250\270.py" "b/H0ngJu/BFS/\353\243\250\353\250\270.py" new file mode 100644 index 0000000..2ccdef8 --- /dev/null +++ "b/H0ngJu/BFS/\353\243\250\353\250\270.py" @@ -0,0 +1,37 @@ +import sys +from collections import deque + +def input(): return sys.stdin.readline().rstrip() + +N = int(input()) +info = [[]] +for i in range(N): + people = list(map(int, input().split())) + info.append(people[:-1]) +M = int(input()) # 최초 유포자 수 +rumor = list(map(int, input().split())) + +answer = [-1] * (N+1) +belive = [0] * (N+1) +time = 0 +q = deque() + +for r in rumor: # 최초 유포자 + q.append([r, 0]) + answer[r] = 0 + +while q: + person, time = q.popleft() + + cnt = 0 + for p in info[person]: + if p == 0: + break + if answer[p] == -1: + belive[p] += 1 + + if belive[p] >= (len(info[p]) + 1) // 2: + answer[p] = time + 1 + q.append((p, time+1)) + +print(*answer[1:]) \ No newline at end of file diff --git a/H0ngJu/README.md b/H0ngJu/README.md index 57ae2b1..e723bdb 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -42,4 +42,4 @@ | 38차시 | 2024.01.06 | 정렬 | [최소 회의실 개수](https://www.acmicpc.net/problem/19598) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/263 | | 39차시 | 2024.01.18 | 정렬 | [컬러볼](https://www.acmicpc.net/problem/10800) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/266 | | 40차시 | 2025.01.28 | 그리디 | [흙길 보수하기](https://www.acmicpc.net/problem/1911) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/267 | -======= +| 41차시 | 2025.02.04 | BFS | [루머](https://www.acmicpc.net/problem/19538) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/270 | \ No newline at end of file