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/24545
🧭 풀이 시간
15분
👀 체감 난이도
✏️ 문제 설명
Y-트리는 아래 조건을 만족하는 트리이다.
정점 N개인 트리에서 정점을 0개 이상 삭제하여 만들 수 있는 가장 큰 Y-트리의 크기를 구해보자.
🔍 풀이 방법
일단 1을 루트로 잡고,
정점 n에 대해 밑으로 가장 긴 길이를 d[n], 밑으로 두 번째로 긴 길이를 dd[n], 세 번째로 긴 길이를 ddd[n], 위로 가장 긴 길이를 u[n]이라 정의
d[n] = max(d[i]) + 1
dd[n] = max2(d[i]) + 1
ddd[n] = max3(d[i]) + 1
u[n] = max(u[p], d[p] == d[n] + 1 ? dd[p] : d[p]) + 1
답은 d[n] + dd[n] + ddd[n] 혹은 d[n] + dd[n] + u[n] 의 최댓값으로 구했다.
⏳ 회고
ez