[20250327] BOJ / G2 / Secret Milk Pipes / 권혁준#289
Merged
ShinHeeEul merged 1 commit intomainfrom Mar 27, 2025
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/27075
🧭 풀이 시간
15분
👀 체감 난이도
✏️ 문제 설명
주어지는 그래프의 두 번째로 작은 스패닝 트리의 비용을 구해보자.
🔍 풀이 방법
[사용한 알고리즘]
크루스칼 알고리즘의 작동 방식을 생각해보면, 두 번째로 작은 스패닝 트리는 최소 스패닝 트리에서 간선이 하나 빠지고 다른 간선으로 대체된 형태라고 생각할 수 있다.
최소 스패닝 트리를 일단 만들어 두고, 여기에 쓰이지 않은 간선들이 대체 간선이 되었을 때 빠져야 하는 간선을 BFS로 구해줬다.
빠져야 하는 간선은, 최소 스패닝 트리 상에서 대체 간선이 잇는 두 정점 사이 경로 중, 가중치의 최댓값이 된다.
⏳ 회고
두 번째로 작은 스패닝 트리를 구하는 문제는 이미 풀었던 유형(https://www.acmicpc.net/problem/1626)이라 금방 풀었는데,
너무 어려운데 이건 왜 골드인지 모르겠다