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/22106
🧭 풀이 시간
35분
👀 체감 난이도
✏️ 문제 설명
초기에 정점이 하나뿐인 트리$T$ 가 있다.
여기에 두 종류의 작업을 할 수 있다.
만들고자 하는 트리$S$ 가 주어지면, 초기 $T$ 에 작업을 수행해야 하는 최소 횟수를 구해보자. (단, 못 만든다면 -1)
🔍 풀이 방법
[사용한 알고리즘]
1번 작업으로는 정점의 차수가 그대로이거나 1 줄어들게 된다.$S$ 에서 차수가 4 이상인 정점이 있다면, 답은 무조건 -1이다.
2번 작업으로는 정점의 차수가 최대 3이 된다.
=> 만들고자 하는 트리
그게 아니면, 차수가 2인 점 아무거나 하나를 초기$T$ 로 둔 뒤에 작업 횟수를 DFS로 구해주면 된다.
⏳ 회고
차수가 2인 점을 아무거나 하나 골라도 최소 횟수가 나온다는 건 증명을 못했다...