Kosaraju: the second DFS forest identifies mutual reachability
ProvedCLRS.SCC.kosaraju_forest_componentsLet be a finite directed multigraph and let be a transpose of , retaining vertex count and reversing every adjacency occurrence with its multiplicity. Suppose a first DFS forest on satisfies the stated parent, event-time, white-path, component-tree and finish-order properties. Suppose a second DFS forest on satisfies the same forest contract, and its outer-loop input order is the reverse of the first forest's increasing finish order.
Then for every pair of vertices of ,
Here is the second forest's tree label and reachability allows zero-edge walks. Thus each second-pass predecessor tree is exactly one strongly connected component of the original graph. The assertion includes empty graphs, self-loops and parallel arcs; labels are not canonical. All execution, heap-allocation and cost questions are separated from this purely mathematical two-forest lemma.
import Definitions.Def_CLRS_DFS_Program set_option autoImplicit false open Algo2LeanGenerated CLRS.GraphTraversal CLRS.DFS
theorem CLRS.SCC.kosaraju_forest_components
(g t : Graph) (transposed : IsTranspose g t)
(q₁ p₁ d₁ f₁ o₁ c₁ q₂ p₂ d₂ f₂ o₂ c₂ : Seq) (k₁ k₂ : Nat)
(first : Forest g q₁ p₁ d₁ f₁ o₁ c₁ k₁)
(second : Forest t q₂ p₂ d₂ f₂ o₂ c₂ k₂)
(reversed : ∀ i : Nat, i < g.size → q₂ (i : Int) = o₁ ((g.size : Int) - 1 - i)) :
∀ u v : Int, Vertex g u → Vertex g v →
(c₂ u = c₂ v ↔ StronglyConnected g u v) := by sorry