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/1043
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
지민이는 파티에서 거짓을 말하려고 한다.
하지만 파티에 진실을 아는 사람이 있으면 그 자리에서는 거짓말을 하면 안 된다.
사람 N명과 파티 M개, 그리고 진실을 아는 사람이 누군지가 주어질 때, 거짓말을 해도 되는 파티의 개수를 구하라.
🔍 풀이 방법
어떤 사람이 진실을 아는 사람과 같은 파티에 한 번이라도 참석하면, 지민이는 그 파티에서 진실을 말해야만 하므로 그 사람도 진실을 알게 된다.
그러니 유니온 파인드를 이용해 풀면 된다.
먼저 각 파티의 파티원들을 전부 union해서, 파티를 통해 연결된 사람들을 같은 집합으로 만든다.
그 다음 진실을 아는 사람들과 같은 집합에 속한 사람이 있는 파티를 제외하고 거짓말이 가능한 파티 개수를 세면 된다.
⏳ 회고
파티가 주어진 순서대로. 진실 아는 사람이 있는 파티면 union하고, 없으면 거짓말 가능으로 카운트 하면 되는 거 아닌가 했다.
근데 문제에 파티 방문 순서는 정해져 있지 않기때문에 그렇게 풀면 안됐다.
union 먼저 쫙 하고 조건에 맞는지 다시 검사해야 한다.