Merged
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/2887
🧭 풀이 시간
90분
👀 체감 난이도
✏️ 문제 설명
행성들이 3차원 좌표로 이루어져있는데 이걸로 MST를 구현하라
🔍 풀이 방법
MST
정점이 10만개라 N^2하면 간선이 너무 많아요
그래서 x랑 y랑 z랑 따로 거리 구해서 가장 짧은 경우의 간선만 얻어내야 해요
인접한 두 행성간 x,y,z 각각 오름차순으로 정렬하고 인접한 두 행성간 간선을 얻어요
그러면 총 약 30만개의 간선을 얻어요
이제 다 우선순위 큐에 넣고 N-1번 연결할때까지 비용을 모으면 정답이에요
⏳ 회고
x,y,z 따로 저장하는 방식으로 했었는데, 생각해보니 이러면 값을 비교하기가 어려워요 1번 행성과 2번 행성의 x,y,z를 비교해야 하는데, 제각각이 되어버려요. 그래서 수정했는데 맞았어요.