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/16562
🧭 풀이 시간
5분
👀 체감 난이도
✏️ 문제 설명
학생 N명이 그래프 형태로 친구관계를 맺고 있다. 학생 i에게 A[i]만큼의 돈을 주면 그 학생이 한달 간 친구가 되어준다.
친구의 친구도 친구이기 때문에, 친구비를 낼 친구를 잘 고르면 적은 돈으로 모든 사람과 친구가 될 수 있다.
가지고 있는 돈이 K원일 때, 모든 학생들과 친구가 될 수 있는지 알아보자.
🔍 풀이 방법
분리 집합을 이용하여 친구 관계가 주어질 때마다 같은 집합으로 union해준다.합칠 때 친구비를 둘 중 더 작은 값으로 취해준다.
답을 구할 때는 집합의 루트에 대한 친구비의 합이 K보다 큰지 판단한다.
⏳ 회고
ㅠㅠ