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/29894
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
정점 N개, 간선 M개인 그래프가 주어지고, 간선에는 가중치가 달려있다.
두께가 K 이상인 간선들로만 이루어진 그래프에서, 직선과 원의 개수를 최소가 되도록 K를 정해보자.
🔍 풀이 방법
간선 리스트로 입력받아서 가중치 순서대로 정렬한다.
이 리스트를 순회하면 K값을 가중치가 큰 순서대로 정해볼 수 있다.
각 정점의 상태를 4가지로 나눴다.
이 때, 상태끼리의 변환 관계는 위에서 아래로 진행된다.
따라서, 각 간선이 추가될 때마다 분리 집합으로 두 정점의 루트의 상태를 확인하고,
각각의 상태에 따라 나올 수 있는 4^2 = 16가지 경우를 모두 if문으로 나눠서 각각 처리해줬다.
16가지 경우 중, 직선 + 직선 -> 원이 되는 경우와 직선 + 직선 -> 직선이 되는 경우를 판단하기 위해 그래프의
차수를 관리해줬다.직선 + 직선이 원 혹은 직선이 되려면, 두 정점의 차수가 모두 1이어야 한다.
⏳ 회고
if문이 16개인데 한 번밖에 안 틀려서 진짜 다행이다