[20250327] BOJ / G3 / Fix Wiring / 권혁준 #290
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/20026
🧭 풀이 시간
10분
👀 체감 난이도
✏️ 문제 설명
정점이 N개인 완전 그래프와, 길이가 N*(N-1)/2인 배열 A가 주어진다.
완전 그래프의 각 간선의 가중치를 배열 A에서 중복되지 않게 배정했을 때, 만들어지는 최소 스패닝 트리의 비용으로 가능한 최솟값과 최댓값을 각각 구해보자.
🔍 풀이 방법
[사용한 알고리즘]
최소 스패닝 트리를 직접 구현하지는 않지만, 최소 스패닝 트리를 만드는 과정을 떠올려야 해결할 수 있다.
일단, 최솟값이 되는 경우는 당연히 배열 A에서 가장 작은 N-1개의 수를 고르는 경우이다.
크루스칼 알고리즘으로 접근하면, 우선 A에서 가장 작은 원소는 반드시 최소 스패닝 트리에 포함되고, 그 다음으로 작은 원소 또한 반드시 포함된다.
그 다음으로 작은 원소는 포함이 안 되도록 할 수 있다. 앞선 두 간선과 싸이클을 이루도록 가중치를 배정하면 이 원소를 건너뛸 수 있다는 의미다.
....
이런 식으로 접근해서 최댓값을 계산해줬다.
⏳ 회고
신기하고 재밌다