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/34016
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
정점 N개인 그래프에서 두 정점 a와 b를 잇는 간선의 가중치는 a+b이다.
사용할 수 없는 간선이 최대 두 개 주어지면, 이 그래프의 최소 스패닝 트리를 구해보자.
🔍 풀이 방법
N이 최대 10억이라 일반적인 MST 구하는 알고리즘을 사용할 수 없다.
조금 관찰을 해보면, 1을 제외한 모든 점을 가능한 1과 이어주는 것이 최적해임을 알 수 있다.
근데 만약 사용할 수 없는 간선 중에 1과 잇는 경우가 존재한다면, 1 대신 그 다음으로 작은 번호와 이어주면 된다.
⏳ 회고
풀이는 간단한데 구현이 그렇지 않다.
고려해야 할 케이스가 적지 않아서 if-else문을 많이 써야 하는데, 이 과정에서 실수하기가 쉽고 이런 유형의 문제는 틀려도 왜 틀렸는지 잘 알 수 없는 게 문제다.