How this calculation works
Find the maximum number of pairwise vertex-disjoint directed simple cycles and return the selected cycles. Unused vertices are allowed; the objective counts cycles rather than covered vertices.
P(S)=max(P(S−{v}), max_{directed cycle C⊆S, v∈C}(1+P(S−V(C)))); P(∅)=0.A worked example
The default graph contains cycle 0→1→2→0 and cycle 3→4→3. They are vertex-disjoint, giving count 2. Vertex 5 is unused. Since loops are excluded, every cycle needs at least two vertices, and this graph has no third eligible cycle.
Good to know
Loopless directed graphs with 1–11 vertices. Opposite arcs form a valid two-cycle. Enumeration stops with an explicit unfinished-search error after 1000000 DFS states. Completed cycle-subset DP is exact; no result is returned as optimal after a cap.
Count cycles rather than vertices
A packing is a family of directed cycles that do not share vertices. Each cycle contributes one to the objective regardless of its length. A packing of three short cycles therefore beats one long cycle even when the long cycle visits more vertices overall.
Unused vertices are allowed and explicitly listed. This is different from a cycle cover, which must assign every vertex to a cycle, and from feedback vertex set, which removes vertices to destroy all cycles. Maximizing the number of disjoint cycles does not directly solve either of those tasks.
Compare this with the Minimum feedback vertex set calculator for a directed graph. Find the largest family of vertex-disjoint directed cycles rather than a vertex set hitting every cycle.
Enter the directed graph carefully
List each arc as source,target using zero-based integer labels within the declared vertex count. Direction matters: 0→1→2→0 is a cycle, while reversing just the last arc may destroy it. Vertices with no incident arcs still count as declared but cannot enter a cycle.
The model excludes loops, so the shortest allowed directed cycle has two vertices with arcs in both directions. Those opposite arcs are distinct and valid. Duplicate arcs, invalid endpoints and extra numeric columns are rejected. Correct the rows and rerun to obtain a new complete search.
Verify the default packing
The first three default vertices form the directed triangle 0→1→2→0. Vertices 3 and 4 have both arcs between them and form a second cycle. The extra arc from 2 to 3 links these regions in only one direction; it does not force their cycles to intersect.
The arc from 4 to 5 leads to a vertex with no return route, so vertex 5 remains unused. The returned count is two. Both selected cycles can be checked arc by arc, including the closing arc from each listed cycle’s last vertex back to its first vertex.
Enumerate canonical cycle subsets
The first stage enumerates simple directed cycles by starting at their smallest vertex label and allowing only larger labels internally. This removes rotation duplicates without discarding any cycle. A visited mask prevents repeated vertices within a candidate path before its closing arc reaches the start.
Different directed cycles can use the same vertex subset. For this objective those alternatives have identical compatibility with every other cycle, so only one representative per subset is necessary. The displayed representative still records its actual directed order; a subset by itself would not verify that the closing arcs exist.
Why the packing recurrence is complete
For any available vertex v, an optimum either leaves v unused or places it in exactly one selected cycle. The recurrence tries both possibilities, subtracting the whole cycle subset before solving the remainder. These alternatives exhaust all vertex-disjoint packings without permitting two selected cycles to reuse v.
Memoization shares answers for repeated available subsets. Reconstructing the chosen branches produces the cycle witness. To verify disjointness, flatten the selected cycles and ensure no label repeats; to verify direction, check consecutive and closing arcs. Exactness depends on completing enumeration before optimizing over its cycle subsets.
Resource limits are not negative results
Even eleven vertices can support a very large number of directed cycles in a dense graph. The enumeration stage therefore counts recursive states and stops after one million. Hitting this limit raises an unfinished-search error and supplies neither a claimed optimum nor a claim that a packing is impossible.
A completed search returning zero is different: it means no directed simple cycle was found after exhaustive enumeration. Reducing dense inputs or removing irrelevant vertices may allow the bounded method to finish, but changing the graph also changes the question. Preserve the original data when recording why a search was unfinished.
Interpretation and complexity boundaries
The subset dynamic program has at most 2048 available-vertex masks, but constructing its cycle choices can dominate runtime. The output reports enumeration and dynamic-program state counts separately. The eleven-vertex cap is a practical exact-search boundary, not a mathematical claim that larger graphs lack efficient special cases.
This page does not optimize cycle weight, cycle length, total covered vertices or an exchange value attached to a cycle. It counts cycles only. If a real application forbids short cycles, requires a maximum cycle length or includes edge capacities, those restrictions must be modeled by a different solver.
A few questions, answered
Do two opposite arcs count as a cycle?
Yes. With loops excluded, a directed two-cycle is valid.
Must every vertex be used?
No. Unused vertices are allowed and listed.
Does a search-limit error mean no packing exists?
No. It means enumeration is unfinished, so no exact maximum is claimed.
Why retain only one cycle per vertex subset?
Cycles using the same vertices have identical disjointness relationships for this cycle-count objective.