[20250711] BOJ / G1 / 트리 / 이종 #435
Merged
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/10838
🧭 풀이 시간
100분
👀 체감 난이도
✏️ 문제 설명
트리에 대한 정보와 일련의 연산이 주어질 때, 각 연산을 효과적으로 실행하는 프로그램을 작성하시오.
연산은 노드 이동, 특정 구간의 엣지에 동일 색상 칠하기, 그리고 특정 구간에 존재한느 색상의 갯수 구하기이다.
🔍 풀이 방법
노드와 엣지 클래스를 따로 구현하려다가 그냥 노드에 color 변수를 도입해서 자신에서 상위 노드로 가는 길의 색상을 저장하게 하였다.
그리고 최소 공통 조상?은 로직이 따로 있는 줄 모르고 자체적으로 생각해보았다.
처음에는 level을 도입하고, 이를 노드 이동할때도 변경되게 하려했다. 그런데 이러면 하위노드의 레벨에는 반여이 안되어서 취소하였고,
그냥 무식하게 set에 때려 넣어서 이미 존재하는 노드면 반환하는 식으로 변경하였다.
⏳ 회고
100분 중 60분은 하위 노드 레벨 전파 안되는거 못찾아서 해메는데 썼다.
디버깅...을... 잘...하자...