Controls
Live Counters
Legend
Tip: use Step to inspect each case in isolation, then Run to see the bridge counter rise and fall as the two triangles form. Reset starts over.
Event Log
How the three cases work
Case A — redundant. The new edge joins two vertices already in the same 2ECC. They are already on a cycle together, so nothing changes: the bridge count stays the same.
Case B — new bridge. The new edge joins two separate components. It is the only link between them, so it is a bridge. The smaller bridge-tree is rerooted and hung under the larger one (small-to-large), and the counter goes up by one.
Case C — cycle closes. The new edge joins two 2ECCs in the same component. It closes a cycle: every bridge on the forest path between them now has a detour and stops being a bridge. Those 2ECCs merge into one at their LCA, and the counter drops by the path length.
Bridge count identity: at every step, bridges = (#2ECC) − (#components). Watch the three counters above confirm this after each edge.
This demo builds two triangles joined by a single bridge. The final state has exactly one bridge — the link between the two triangles. Press Run to watch the whole sequence, or Step to advance one edge at a time.
Reading the two views
Top — real graph. Vertices 0–5 with the edges added so far. Bridge edges are drawn thick orange; non-bridge edges (inside a 2ECC) are green. The just-added closing edge in a Case C flashes purple and dashed. Each vertex is outlined in the color of its 2ECC group.
Bottom — bridge forest. Every 2ECC is collapsed to one blue node labelled with its member vertices, e.g. {0,1,2}. The lines between forest nodes are exactly the current bridges. During a Case C, the nodes being compressed into one are outlined red before they merge.
The forest is the data structure's mental model: add_edge is always a forest operation — link a tree (Case B) or contract a path to the LCA (Case C).