Proofs: Block-cut tree
These are the human proofs of Block-cut tree, at full length.
The block-cut tree is a forest, and its queries are correct full
This proof shows: correctness.
Let be an undirected graph. Parallel edges are allowed; loops are ignored, since they lie in no block with another edge and change no articulation point. Line L1 gives the vertex sets of the blocks of the non-loop edges (correct by the proof on the Hopcroft-Tarjan page), plus a block for each vertex with no non-loop edge, and the set of articulation points. We use these facts from the biconnected components page: two blocks share at most one vertex; a vertex lies in two or more blocks if and only if it is in ; and two edges at a vertex that lie in different blocks are not joined by a path that avoids (fact 3). We also use that is connected in for every block and every vertex : a block with two vertices becomes one vertex, and a block with three or more vertices is biconnected.
Let be the graph built by lines L2 and L3: a node for each block, a node for each , and an edge whenever .
Lemma 1. is a forest, and its trees match the components of .
Proof. Each node of lies in one component of , and two nodes are adjacent only if they share a vertex, so a tree of stays in one component. Within a component, any two blocks are joined in : follow a path of from one to the other; each time it moves from one block to the next, it does so at a shared vertex, which is in , so the two block nodes have a common neighbour.
We show that each edge is a bridge of , so has no cycle. Since , it lies in a second block . Suppose minus the edge still has a path from to . Then it is with and all . Each is connected in , and consecutive ones share , so has a path from a neighbour of in to a neighbour of in . The edges and lie in different blocks, and this path joins them without , which contradicts fact 3.
Line L5 roots each tree of at a block node, and one depth-first search of gives each node an interval . The intervals of a node and of its descendants are nested, and those of two nodes that are not ancestor and descendant are disjoint. So line L6 is the ancestor test, and in line L7 the children of are sorted by , so the last child whose is at most is the one whose subtree holds .
Line L4 sets for , and otherwise the only block that holds . Thus the blocks that hold are the tree neighbours of if , and if not.
Lemma 2 (SEPARATES). Let be distinct, with and in one component. Every - path of passes through if and only if and lies on the tree path between and .
Proof. Let be a - path. Cut at each vertex where it passes from an edge of one block to an edge of another block. Each such vertex is in , and the blocks of in order, with the nodes between them, form a walk in from a neighbour of (or the node) to the same for . In a tree, every walk between two nodes visits each node of the path between them. So if is on that path, is on the walk, and passes through .
Conversely, let not be on the tree path . For each block on it, let and be the vertices where the path enters and leaves it: the vertex of the cut node before and after it, or at the start and at the end. None of these is , since is not on the path and . Since is connected in , it has an - path without . Joining these paths gives a - walk without , so some - path avoids . If , has as many components as , and , stay joined.
The tree path between and passes through if and only if is an ancestor of exactly one of them, or is an ancestor of both and they lie under different children of (or one of them is ; here ). Lines L9 to L12 compute this test, and line L8 handles . So SEPARATES is correct.
Lemma 3 (SAME-BLOCK). For distinct and , lines L13 to L16 return true if and only if some block holds both.
Proof. Let be the set of blocks that hold , as given above. A common block exists if and only if . If neither vertex is in , the sets are and , so the test is (line L14). If only is in , the block is in if and only if is adjacent to , that is, is the parent or a child of (line L15). If both are in , a common block is adjacent to both cut nodes. It cannot be a child of both. So it is the parent of both, or the parent of one and a child of the other, which makes the other the grandparent of the first (line L16). Cut nodes are never roots, so their parents exist.