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/30691
🧭 풀이 시간
25분
👀 체감 난이도
✏️ 문제 설명
정점 N개인 트리의 각 간선엔 가중치가 달려있다.
어떤 정점을 골라서, 그 정점을 포함하여 정점의 자손들 중 거리가 K 이하인 모든 자손들을 뽀갤 수 있다.
최대 몇 개를 뽀갤 수 있는지 구해보자.
🔍 풀이 방법
DFS로 리프 정점부터 올라오면서 각 노드 별로
해당 정점까지 오는 경로의 거리를 우선순위 큐로 관리한다.두 노드의 정보를 합칠 때는 smaller to larger로 합쳐주는데, 자식 사이즈가 부모 사이즈보다 큰 경우를 대비하기 위해 가상의 가중치 배열 v를 둬서 실제로는 거리가 K-v[n] 일 때 우선순위 큐에서 poll해준다.
⏳ 회고
좀 헷갈림