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/10888
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
두 섬간의 다리를 연결할 때, 그 당시의 이동할 수 있는 섬의 쌍 개수와 그때마다 쓰이는 다리의 개수의 합은?
🔍 풀이 방법
문제에서 (i, i+1)의 섬을 연결한다. 쌍의 개수와 다리의 합을 변수로 놓고 상태관리를 진행한다.
각 섬의 root의 size를 기준으로 쌍의 개수와 다리의 합을 빼고, 더한 거의 개수를 더한다.
제일 중요한 것은 점화식이다. (i, i+1)의 섬을 연결하기 때문에, 점화식으로 개수 관리가 가능했다.$size(size-1)/2$ $size(size^{2}-1)/6$
섬의 쌍 개수:
다리의 합:
⏳ 회고
섬의 쌍 개수는 아는 점화식인데, 다리의 합은$1*(n-1) + 2*(n-2) + ... + (n-1)*1$ 인 걸 아는데 점화식을 못 구해서 클선생에게 점화식을 작성해달라고 했다.
또, size를 관리할 때 범위 때문에 long으로 했어야 했는데, int로 해서 틀렸다.