Advanced maths

Minimum vertex disjoint path cover calculator for a DAG

Partition all vertices of a directed acyclic graph into the fewest vertex-disjoint directed paths.

Your numbers

Vertices are labeled 0 through n−1, including isolated vertices.
One edge per line: u,v. No loops or duplicate pairs. Blank means no edges.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Partition all vertices of a directed acyclic graph into the fewest vertex-disjoint directed paths. Return the paths, a maximum split-graph matching and an equally sized vertex-cover certificate.

THE FORMULAminimum path count = |V|−|M_max|, using a left and right copy of every vertex and one split edge u_L v_R for each original arc u→v.

A worked example

For arcs 0→1→2 and 0→3→4→5, the cover [0,1,2] and [3,4,5] uses two paths. A matching has four links. The two sinks 2 and 5 require distinct final path vertices, so one path cannot cover this graph.

Good to know

Loopless DAGs with 1–150 vertices. Uses original arcs, not transitive closure. A path may be a single isolated vertex. Cyclic inputs are rejected. Augmenting-path matching is polynomial, O(nm) here; no weighted path preference.

Partition vertices into actual paths

A path cover assigns every vertex to exactly one directed path. Consecutive vertices within each path must be linked by an entered arc, and a one-vertex path is allowed. The objective is to minimize the number of paths, with no preference among different covers of equal size.

This is useful when a chain must follow explicitly available transitions while visiting each item once. It differs from finding one longest path, covering only selected vertices, or allowing several paths to share a vertex. Those alternatives have different feasible solutions and cannot be inferred from this result.

A maximum matching links two path componentsTwo vertex-disjoint directed paths0123450 → 1 → 23 → 4 → 5Six vertices − four matching links = two paths
Scroll across to see the full diagram.
For arcs 0→1→2 and 0→3→4→5, the cover [0,1,2] and [3,4,5] uses two paths. A matching has four links. The two sinks 2 and 5 require distinct final path vertices, so one path cannot cover this graph.

Compare this with the Maximum bipartite matching calculator from an edge list. Partition every DAG vertex into the fewest directed paths and return those paths.

Keep arc direction explicit

Enter the number of vertices and each directed arc as source,target. Labels run from zero to n−1. Both 0,1 and 1,0 would form a directed cycle and are therefore unsuitable for this calculator. The page checks acyclicity before running the path-cover reduction.

All declared vertices are covered, including isolated vertices absent from the arc rows. Loops, duplicate arcs, invalid labels and fractional endpoints are rejected. Reversing an arc can change both feasibility and the optimum. Correct invalid input and calculate again rather than interpreting a partial topological ordering as a solution.

Check the two chain example

The default graph branches after vertex 0. One branch reaches sink 2 through vertex 1; the other reaches sink 5 through vertices 3 and 4. The cover [0,1,2] and [3,4,5] assigns all six labels exactly once and uses only entered arcs.

These two paths contain four within-path links in total, so their split-graph matching has size four. Both sinks must end a path, which independently proves that at least two paths are needed. The matching formula then gives six minus four equals two, agreeing with this direct lower bound.

Why matching gives the answer

Make a left copy and a right copy of every original vertex. An arc u→v becomes an edge from u’s left copy to v’s right copy. Choosing a matching ensures that no original vertex has more than one selected successor or more than one selected predecessor.

Because the original graph is acyclic, the selected links cannot form directed cycles. They therefore form disjoint paths covering all vertices after singleton vertices are included. Every selected link reduces the number of paths by one. Maximizing the matching consequently minimizes the number of paths to n minus matching size.

Inspect both certificates

The returned paths are the direct construction certificate. Check that their flattened vertex lists contain each declared label exactly once and that every consecutive pair appears in the input. The matching list records which original arcs link vertices inside those paths, providing a second view of the same construction.

The minimum split-graph vertex cover supplies the matching upper bound. Its left and right labels refer to different copies, so the same numeric label may legitimately appear on both sides. Every split edge must touch this cover, and its total size equals the matching size, certifying maximum matching.

Do not insert reachability links

This implementation uses original arcs without adding transitive closure. If a vertex can reach another through an intermediate vertex, that fact alone does not permit those endpoints to be consecutive in a returned path. A direct transition must exist in the supplied graph.

This detail separates the page from some chain-partition formulations for partially ordered sets, where comparability links represent arbitrary reachability. Adding closure edges changes the operational meaning of a step and may change the minimum path partition. Decide whether a transition means one actual arc or a reachability relation before entering data.

Complexity and rejected models

The vertex limit is 150. Repeated augmenting-path searches compute a maximum matching in polynomial time, with a straightforward O(nm) bound for this implementation. Topological validation, path reconstruction and the alternating-reachability certificate add only polynomial work. Sparse graphs and isolated vertices remain fully represented.

A directed cycle invalidates the reduction from selected links to paths, because a matching could then select a closed cycle. The calculator rejects that model instead of returning n minus matching size as a false path count. Weighted preferences and general-digraph path covers require other optimization methods.

A few questions, answered

Can an isolated vertex be covered?

Yes. It appears as a one-vertex path.

Does the algorithm add transitive closure?

No. Every consecutive pair in an output path must be an entered arc.

Why are cycles rejected?

Matching links in a cyclic graph can form cycles rather than paths, invalidating this reduction.

What proves the matching is maximum?

The returned split-graph vertex cover touches every split edge and has the same size as the matching.

Find your calculator

Start typing to explore the library.