[20250429] BOJ / P2 / 민혁이의 게임 파티 / 권혁준#321
Merged
ShinHeeEul merged 1 commit intomainfrom Apr 29, 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/16976
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
N개의 정점으로 이루어진 그래프가 있고, 각 점에는 1부터 M까지의 수 중 하나가 쓰여있다.
간선이 주어지면, 차례대로 그래프에 추가한다.
1부터 M까지의 각 수에 대해, 이들이 그래프 상에서 연결되는 시점을 구해보자.
🔍 풀이 방법
[사용한 알고리즘]
분리 집합으로 간선 연결을 처리한다.
분리 집합에서 관리하는 루트 점에 대해, multiset을 이용해서 각 점에서 접근 가능한 모든 수의 집합을 관리한다.
간선을 연결할 때는, 두 multiset을 smaller to larger 테크닉으로 합쳐준다.
⏳ 회고
자바에는 multiset이 없어서 어쩔 수 없이 C++로 짰다.
답을 구할 때, 처음 연결될 때 한 번만 기록해야 하는데 여러 번 기록해서 틀렸다.
코드를 신중하게 짜도록 하자