-
[SWEA] 1248. [S/W 문제해결 응용] 3일차 - 공통조상 -GraphProblem_Solving/Graph 2019. 2. 6. 23:14
이 글은 SW Expert Academy에 있는 문제를 풀고 정리한 글입니다.
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV15PTkqAPYCFAYD
이 문제는 크게 두 부분으로 나눠집니다.
1. 트리에서 공통 조상 찾기
2. 부분 트리안에 있는 노드 수 구하기.
먼저 트리를 어떻게 표현할건지 고민했는데
구조체/클래스로 표현하기보다는
이 문제의 경우에는 부모-자식 관계를 배열로 저장하면 좋을것 같았습니다.
이렇게요 ㅎㅎchild의 개수는 0이상 2 이하일수 있으니 2차원 벡터로 설정했습니다.이렇게 하면 자손 노드의 개수를 쉽게 파악할 수 있겠죠.'Problem_Solving > Graph' 카테고리의 다른 글
[SWEA] 3135. 홍준이의 사전놀이 (0) 2020.01.05 [SWEA] 2891. 분수 스도쿠 - DFS & 가지치기 (0) 2019.02.11 댓글