[20250831] BOJ / G5 / 트리와 쿼리 / 김민진 #784
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.
🧷 문제 링크
트리와 쿼리
🧭 풀이 시간
20분
👀 체감 난이도
✏️ 문제 설명
주어진 트리에서 서브트리의 노드 수 구하기
🔍 풀이 방법
DFS 돌면서
dp배열에 서브트리의 노드 수 저장해두고 출력만 해주면 됩니다.다만 부모 노드부터 들어오는 게 아니라서 양방향으로 저장하고 방문 처리를 했습니다.
그래서 중간에 루트 노드가 자식 노드로 확인되는 경우가 있는데 방문 처리 하면서 같이 건너뛰었습니다.
서브트리는 본인도 포함이라
cnt는 1부터 시작합니다.⏳ 회고
트리라고 명시되어도 자식 노드부터 나올 수 있다..