Online Bridge Finding — Incremental 2-Edge-Connectivity

Add edges one at a time. Watch bridges appear (Case B) and a closing cycle compress a path of bridges into one 2ECC (Case C).
Two DSUs + a bridge forest maintain the exact bridge count online — no recomputation.

Controls

Slow Fast

Live Counters

Bridges
0
2ECC
6
Components
6
Next edge
(0,1)

Legend

Bridge edge / new bridge
Non-bridge (inside a 2ECC)
2ECC super-node (forest)
Closing edge (Case C)
Path being compressed

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

Real graph (vertices & edges)
Bridge forest (each 2ECC collapsed to one node; edges = bridges)
Press Step to add the first edge. The forest below shows each 2-edge-connected component as a single blue node; the lines between them are exactly the current bridges.

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).