[20251221] BOJ / D5 / Graph Construction / 권혁준 #1721
Merged
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/22561
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
정점 N개인 그래프에서 아래 쿼리들을 처리해보자.
🔍 풀이 방법
쿼리의 순서를 시간으로 보면, 각 간선의 라이프사이클을 계산해놓을 수 있다.
간선들의 추가 삭제를 시간 순서에 따라
분리 집합에서 union, rollback하는 것으로 구현할 수 있다.rollback 작업은 union의 역순으로 이루어져야 하기 때문에, 간선의 라이프사이클 하나를
분할 정복을 통해 O(logN)개로 쪼갠다.-> 간선의 라이프사이클이 분할 정복의 한 노드가 나타내는 시간 구간을 갖도록 구현한다.
모든 간선에 대한 라이프사이클 전처리를 해주고, 마지막에 분할 정복 한 번으로 답을 구해줬다.
⏳ 회고
분리 집합에 rollback을 구현할 때는 path compression 대신 다른 최적화 방식을 써야 하는데 까먹어서 틀렸었다.