[20250509] BOJ / D5 / Confuzzle / 권혁준 #330
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/20297
🧭 풀이 시간
30분
👀 체감 난이도
✏️ 문제 설명
각 정점에는 수가 적혀 있으며, 적어도 두 정점은 같은 값임이 보장된다. 이때, 서로 같은 값이 쓰여 있는 두 정점 쌍 중 가장 거리가 가까울 때의 거리를 구해보자.
🔍 풀이 방법
[사용한 알고리즘]
리프 노드에서부터 올라오며 (정점 고윳값, 거리)를 Map으로 관리한다.
두 정점 사이의 거리를 구해야 하기 때문에, 거리를 저장할 때는 가장 짧은 거리 두 개만 저장한다.
Map을 합칠 때는 Smaller to Larger로 합쳐준다.
⏳ 회고
센트로이드를 공부하고 연습 문제로 풀려했는데,
정작 센트로이드 없이 푸는 게 더 직관적인 것 같다.