[20260109] BOJ / G3 / 사회망 서비스(SNS) / 이강현#1781
Merged
ShinHeeEul merged 1 commit intomainfrom Jan 9, 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/2533
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
트리 구조의 그래프에서 모든 인원이 정보를 습득하는 것이 목표
인원들을 각각 얼리어댑터거나 일반인임.
정보를 습득하는 인원은 얼리어댑터들이고 일반인들은 자신과 연결관계를 맺은 모든 인원들이 얼리어댑터이어야 정보를 습득할 수 있음.
모든 인원들이 정보를 습득할 수 있도록 하는 최소 얼리어댑터의 수를 출력하자.
🔍 풀이 방법
트리 dp
dp[현재 인원][인원 타입]으로 정의하고 이는 현재 인원을 포함하고 이 인원의 자식 트리가 모두 정보를 습득할 수 있게끔하는 최소 얼리어댑터의 수를 나타냄.
현재 인원이 일반인이라면 이와 연결관계를 맺은 모든 인원들은 얼리어댑터여야함.
하지만 얼리어댑터라면 연결관계를 맺은 모든 인원이 일반인이거나 얼리어댑터일 수 있음.
0을 일반인, 1을 얼리어댑터라고 판단했을때,
dp[현재 인원][0] += dp[다음 인원][1]이고
dp[현재 인원][1] += Math.min(dp[다음 인원][0], dp[다음 인원][1])로 정의하면 조건을 만족할 수 있음.
⏳ 회고
처음에는 같은 depth에 있는 인원들은 모두 얼리어댑터거나 일반인이라고 생각하고 문제를 풀었는데,
현재 인원이 얼리어댑터일때, 다음 인원이 꼭 일반인인게 최적해를 보장하지 않는다는 반례를 알게 되었다.
트리 dp라는 유형을 처음 풀어봐서 다소 어려웠다.