DSU Rollback Hot Sheet¶
Use this page when the problem is still fundamentally about connectivity, but deletions or undo now block plain DSU.
Do Not Use When¶
- only additions exist, so plain DSU hot sheet already fits
- the problem is truly online and future events are unknown
- the real question is path aggregate, shortest path, or subtree structure
- one monotone offline sweep already solves the problem without rollback
Choose By Signal¶
- add/remove edge timeline is fully known, and you need connectivity or component counts after each step ->
dsu-rollback-dynamic-connectivity.cpp - the real blocker is deletions, not graph modeling -> reopen DSU Rollback / Offline Dynamic Connectivity
- the problem is offline, but one sorted sweep is enough -> compare Offline Tricks hot sheet
- components only merge -> back down to DSU hot sheet
Core Invariants¶
- ordinary path compression is not the default here because every change must be undoable exactly
- each successful union records one reversible change on a stack
- an edge active on
[l, r)is assigned toO(log q)nodes of a segment tree over time - at DFS leaf
t, the DSU represents exactly the graph after the firsttevents
Main Traps¶
- getting the time model wrong: add at
imeans active from statei, remove atimeans inactive at statei - forgetting that initial edges start at time
0 - using ordinary path compression and then being unable to rollback cleanly
- not taking one snapshot per DFS node before applying that node's batch
Exact Starters In This Repo¶
- exact starter ->
dsu-rollback-dynamic-connectivity.cpp - flagship in-lane rep -> Dynamic Connectivity
- merge-only compare point -> DSU hot sheet
- family compare point -> Offline Tricks hot sheet
Reopen Paths¶
- full lesson and time-segmentation proof shape -> DSU Rollback / Offline Dynamic Connectivity
- merge-only baseline -> DSU
- family chooser -> Offline Tricks
- broader structure chooser -> Data structures cheatsheet