Skip to content

Conversation

@zinnnn37
Copy link
Contributor

@zinnnn37 zinnnn37 commented Aug 31, 2025

🧷 문제 링크

트리와 쿼리

🧭 풀이 시간

20분

👀 체감 난이도

✏️ 문제 설명

주어진 트리에서 서브트리의 노드 수 구하기

🔍 풀이 방법

DFS 돌면서 dp 배열에 서브트리의 노드 수 저장해두고 출력만 해주면 됩니다.
다만 부모 노드부터 들어오는 게 아니라서 양방향으로 저장하고 방문 처리를 했습니다.
그래서 중간에 루트 노드가 자식 노드로 확인되는 경우가 있는데 방문 처리 하면서 같이 건너뛰었습니다.
서브트리는 본인도 포함이라 cnt는 1부터 시작합니다.

⏳ 회고

트리라고 명시되어도 자식 노드부터 나올 수 있다..

@ShinHeeEul ShinHeeEul merged commit 996cba6 into main Aug 31, 2025
1 check passed
@zinnnn37 zinnnn37 added the success 👍 해설을 보지 않고 풀었을 때 label Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

success 👍 해설을 보지 않고 풀었을 때

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants