Skip to content

Conversation

@oncsr
Copy link
Contributor

@oncsr oncsr commented Aug 12, 2025

🧷 문제 링크

https://www.acmicpc.net/problem/30691

🧭 풀이 시간

25분

👀 체감 난이도

✏️ 문제 설명

정점 N개인 트리의 각 간선엔 가중치가 달려있다.
어떤 정점을 골라서, 그 정점을 포함하여 정점의 자손들 중 거리가 K 이하인 모든 자손들을 뽀갤 수 있다.
최대 몇 개를 뽀갤 수 있는지 구해보자.

🔍 풀이 방법

  • 우선순위 큐
  • smaller to larger

DFS로 리프 정점부터 올라오면서 각 노드 별로 해당 정점까지 오는 경로의 거리를 우선순위 큐로 관리한다.

두 노드의 정보를 합칠 때는 smaller to larger로 합쳐주는데, 자식 사이즈가 부모 사이즈보다 큰 경우를 대비하기 위해 가상의 가중치 배열 v를 둬서 실제로는 거리가 K-v[n] 일 때 우선순위 큐에서 poll해준다.

⏳ 회고

좀 헷갈림

@oncsr oncsr added the success 👍 해설을 보지 않고 풀었을 때 label Aug 12, 2025
@ShinHeeEul ShinHeeEul merged commit 8f1fbf8 into main Aug 12, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

success 👍 해설을 보지 않고 풀었을 때

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants