[20250327] BOJ / P2 / King's Roads / 권혁준 #291
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/19464
🧭 풀이 시간
80분
👀 체감 난이도
✏️ 문제 설명
초기에 정점이 N개, 간선은 없고 정점에 가중치가 달려있는 그래프가 주어진다.
i번 정점의 가중치는 A[i]이고, 이 값은 0 이상 M 미만이다.
이 그래프 상에서 i번 정점과 j번 정점을 잇는 간선을 추가할 때, 그 간선의 가중치는 A[i] + A[j]를 M으로 나눈 나머지가 된다.
이 그래프에 간선을 적절히 추가해서 연결 그래프로 만들고, 그 때의 최소 스패닝 트리 비용을 최소화해보자.
🔍 풀이 방법
[사용한 알고리즘]
먼저, 정점 가중치 배열을 정렬시킨다.
투 포인터를 s = 1, e = N으로 세팅한다.
위 과정은 초기에 주어지는 정점 가중치가 모두 M 미만이기 때문에 가능하다.
⏳ 회고
떠올리기 진짜 어려웠다