Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧷 문제 링크
https://www.acmicpc.net/problem/33626
🧭 풀이 시간
35분
👀 체감 난이도
✏️ 문제 설명
루트 정점이 P이고 정점 N개인 트리가 있다.
루트를 제외한 각 정점에는 학생이 한 명씩 있다.
처음에 학생 M명을 골라서 뱀파이어로 만들 수 있다. 이 때 걸리는 시간은 1초이다.
뱀파이어들은 1초에 한 번씩, 정점 P를 향해 이동하며 뱀파이어가 아닌 학생을 만나면 뱀파이어로 만든다.
모든 학생이 뱀파이어가 되는 최소 시간을 구해보자.
🔍 풀이 방법
f(t) = 시간 t 이내에 모든 학생을 뱀파이어로 만들 때 필요한 초기 뱀파이어 수이 f(t)는 t에 대한 단조감소 함수이다.
따라서 f(t) <= M이 되는 t의 최솟값을 구하면 된다.
-> f(t)를 한 번 구하는 데 O(N)이라면, t에 대한
이분 탐색을 통해 O(NlogN)에 가능dfs로 f(t)를 구해줬다.그리고 f(INF) = 리프노드의 개수이기 때문에 M이 리프노드의 개수보다 작으면 -1 출력
⏳ 회고
생각보다 많이 까다로웠다