[20250815] BOJ / D5 / 정기 모임 / 권혁준 #669
Merged
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/18196
🧭 풀이 시간
70분
👀 체감 난이도
✏️ 문제 설명
정점 N개인 트리의 각 간선에 정수 가중치가 달려있다.
두 점 사이의 거리는 둘을 잇는 경로 상의 간선 가중치 중 최댓값으로 정의한다. (가중치의 합이 아님...)
Q개의 모임이 개최되며, i번째 모임에는 s[i]부터 e[i]번 점에 사는 사람들이 참석한다.
모임을 개최할 장소를 잘 정해서, 사람들이 그 장소까지 이동하는 거리의 최댓값을 최소화해보자.
🔍 풀이 방법
문제를 재해석하면, 구간 [s,e]에 속한 모든 쌍 간의 단순 경로에 속한 최대 가중치를 빠르게 찾는 것이 목적이다.
구간 [s,e]의 최소 공통 조상을 구하고, 그 과정에서 간선 가중치의 max를 구하면 된다.
두 점 a, b의 최소 공통 조상을 구하는 연산을 lca(a,b)라고 하자.
이 lca 연산은 교환법칙과 결합법칙이 성립한다.
근데 구간 lca를 구해야 한다.
-> lca연산을 하는 세그먼트 트리를 떠올렸다.
희소 배열로 전처리를 해놓으면, 최소 공통 조상과 간선 가중치의 최댓값을 lca연산 안에서 같이 구할 수 있다.
⏳ 회고
거리가 가중치 합인 줄 알고 시간 날림