260126 : [BOJ 12784] 인하니카 공화국 #2332
Open
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.
🚀 이슈 번호
Resolve: {#2331}
🧩 문제 해결
스스로 해결: ✅
🔎 접근 과정
해당 문제의 조건은 그래프 중에서도 "트리" 라는 것을 알려준다.
따라서 각 노드에 대해 자식노드를 쭉 타고 내려갔을 때의 weight들 중 가작 작은 값을 기록한다.
이렇게 하여 기록된 weight 들을 합산하여 해당 노드의 총 weight를 구할 수 있다.
이러한 weight들을 합산해가면서 min 값을 계산하면 된다.
⏱️ 시간 복잡도
O(N+E)해당 문제는 단순 DFS로 풀 수 있으므로
DFS의 시간복잡도인 O(N+E)와 같다.
💻 구현 코드