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/15491
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
N개의 도시가 트리 형태로 구성되어 있다.
각 도시들은 정비가 필요하고, 정비에는 정비 기기가 필요하다.
어떤 도시에 필요한 정비 기기의 최소 가격이 x면, 가격이 x 이상인 정비 기기를 사용해야 그 도시를 정비할 수 있다.
어떤 도시를 하나 골라서 그 도시를 없애고 그와 직접 연결된 간선도 제거할 때, 모든 도시를 정비하는 최소 비용 중 최댓값을 구해보자.
🔍 풀이 방법
도시를 없앴을 때 나뉘어지는 각 컴포넌트 S1, S2, ...에 대하여,
max(S1) + max(S2) + ... 를 최대화
inmx[n] = n의 서브트리 내의 최댓값
outmx[n] = n의 서브트리 외의 최댓값
ex[n] = p의 자식들 들 중 n을 제외한 c1, c2, ...에 대하여, max(inmx[c1], inmx[c2], ...)
-> outmx[n] = max(outmx[p], a[p], ex[n])
n의 서브트리 중 n을 제외한 최댓값은 n의 자식들의 inmx 최댓값임.
그래서 n의 자식들 i에 대해, inmx[i]들의 최댓값을 mx1, 두 번째 최댓값을 mx2라고 했을 때
inmx[i] = mx1이면 ex[i] = mx2이고 아니면 ex[i] = mx1
⏳ 회고
ez