[20250903] BOJ / D4 / 그래프와 연결성 쿼리 / 권혁준 #811
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/34226
🧭 풀이 시간
180분
👀 체감 난이도
✏️ 문제 설명
정점 N개, 간선 M개인 그래프에서 l번 이상 r번 이하인 간선들만 사용할 때, 서로 연결되어 있는 정점 쌍의 수를 Q번 구해보자.
🔍 풀이 방법
mo's로 l, r 포인터의 이동 횟수를$O(M\sqrt{M})$ 으로 제한한 뒤에 rollback union-find를 이용해서 [0, Q)의 시간 축을 기준으로 분할 정복하고 각 시간별 쿼리의 답을 구해줬다.
근데 시간 초과임.
⏳ 회고
mo's 자체가$O(M\sqrt{M})$ 이라 분할 정복을 적용하면 로그의 시간이 붙어서 시간 초과가 나는 것 같다.
그래도 버킷 사이즈를 잘 깎으면 뚫릴 줄 알았는데 절대 안 뚫림.
포인터의 이동 성질을 잘 파악하면 분할 정복 없이 그냥 rollback union-find만으로도 될 수도 있을 것 같은데 내일 해봐야겠다.