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/11812
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
자식을 K개 갖는 K진 트리에서 특정 노드 두 개의 값이 주어질때 그 두 노드 사이의 거리를 출력하는 문제.
🔍 풀이 방법
2,3,4진 트리를 각각 depth 3까지 그려보고 x가 주어질때 부모노드를 찾는 함수, x가 주어질때 깊이를 알려주는 함수 두 개를 구현했다. 이후 두 노드의 깊이 차이를 구해서 더 깊은 노드를 같은 깊이까지 맞춘 후 함께 올라오면서 부모가 같아질때까지의 거리를 계산했다.
⏳ 회고
처음에 number format exception이 생겨서 int가 아닌 long을 써야함을 알았고 큰 값이 들어오는 것을 의식해서 큰 값을 넣어보던 중 계산이 너무 오래 걸리는 테스트 케이스가 있었는데 1진 트리인 경우 노드의 개수가 곧 실행시간이라서 노드의 차를 바로 반환하도록 예외처리를 해주어야 했다. k진 트리의 특성을 알게 되었다.