[20260324] BOJ / P2 / Maximum Strategic Savings / 권혁준#2042
Merged
ShinHeeEul merged 1 commit intomainfrom Mar 24, 2026
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/16025
🧭 풀이 시간
20분
👀 체감 난이도
✏️ 문제 설명
N개의 행성이 존재하며, 각 행성에는 M개의 도시가 있다.
행성 e의 도시 f를 (e, f)와 같이 표기한다.
P종류의 간선 (a, b, c)는 임의의 행성 i에 대해, (i, a)와 (i, b)를 잇는 비용 c의 간선을 의미한다.
Q종류의 간선 (x, y, z)는 임의의 도시 j에 대해, (x, j)와 (y, j)를 잇는 비용 z의 간선을 의미한다.
모든 도시의 모든 행성들이 서로 연결되도록 하는 최소 비용을 구해보자.
🔍 풀이 방법
P종류의 간선은 도시 간의 이동에만 관여하고, Q종류의 간선은 행성 간의 이동에만 관여한다.
P종류의 간선을 아무리 연결해봤자 행성 간의 이동 가능 여부는 변하지 않는다.
즉, 도시에 대한 MST와 행성에 대한 MST로 분리하여 생각해도 무관하며, 이때는 연결해주는 간선의 개수만 잘 관리해주면 된다.
구체적으로, P종류의 간선 하나를 추가할 때는 그 시점에 존재하는 행성 컴포넌트의 개수만큼 그 간선이 추가되며,
Q종류의 간선 하나를 추가할 때는 그 시점에 존재하는 도시 컴포넌트의 개수만큼 그 간선이 추가된다.
⏳ 회고
ee