Advanced maths

Minimum spanning arborescence calculator for a directed graph

A directed spanning arborescence is a rooted branching that reaches every vertex by following arrow directions.

Your numbers

Vertices are indexed 0 through n−1.
Rows from,to,weight; absent weight means one. Leave empty for 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

A directed spanning arborescence is a rooted branching that reaches every vertex by following arrow directions. This calculator checks reachability and enumerates a bounded collection of parent assignments, rejecting directed cycles. It returns the minimum-cost out-arborescence or identifies vertices unreachable from the chosen root.

THE FORMULAmin Σ_(e in T) w_e, with one incoming edge per nonroot and a directed root path to every vertex.

A worked example

With root zero, edges 0→1 cost three, 0→2 cost five and both 1→2 and 2→1 cost one, choosing the cheapest incoming edge for each nonroot creates a cycle. The valid optimum instead uses 0→1 and 1→2, with total cost four.

Good to know

At most ten vertices and 300,000 possible parent assignments. Simple directed input without loops. Out-arborescence convention only. Negative finite edge costs are allowed; unreachable and resource-limit cases are distinguished. No undirected-tree substitution.

Direction and root define the branching

An out-arborescence begins at the selected root and follows directed edges toward every other vertex. Each nonroot vertex has exactly one incoming selected edge and the root has none. Reversing every arrow would define an in-arborescence problem, which this page does not silently substitute when an intended route is unreachable.

Before optimization, a reachability traversal finds vertices that cannot be reached from the root in the supplied graph. No spanning out-arborescence can exist in that case. Reporting those vertices is a concrete infeasibility witness; it differs from merely exhausting a computational budget while considering an otherwise reachable graph.

A rooted directed branching must break the cheapest-parent cycle0120 → 1: cost 31 → 2: 1Root: 0Total: 4Reject 1↔2 cycle
With root zero, edges 0→1 cost three, 0→2 cost five and both 1→2 and 2→1 cost one, choosing the cheapest incoming edge for each nonroot creates a cycle. The valid optimum instead uses 0→1 and 1→2, with total cost four.

The Minimum spanning tree calculator from weighted edges covers the nearby task. Directed rooted reachability constraints are absent from an undirected spanning tree.

Cheapest incoming edges can create cycles

Choosing the least costly incoming edge independently for each vertex can create a directed cycle among nonroot vertices. That selection may satisfy local indegree constraints while having no root path. The exact parent-assignment search therefore checks the whole parent chain for every nonroot before accepting a candidate cost.

The default graph makes the issue visible because both cheap cross-edges form a two-cycle. One more expensive root edge must replace part of that local choice. The returned optimum shows that maintaining the rooted global structure, rather than only minimizing separate edge prices, determines the correct total.

Reachability and resource limits are separate outcomes

Every valid candidate contains one incoming edge for each nonroot and reaches the root when parent links are followed backward. Those conditions provide an inspectable structural certificate alongside the cost. Negative edge costs are allowed because the finite branching cannot repeatedly traverse a profitable cycle; repeated walks are not the optimization object.

The product of incoming-choice counts bounds the exhaustive search before it begins. Inputs requiring more than the declared assignment cap are rejected without a cost or optimum claim. Reference tests independently enumerate tiny parent maps and compare established arborescence solvers, keeping unreachable, unsupported-size and valid-optimum outcomes distinct.

Distinguish an out-arborescence from an undirected tree

A rooted out-arborescence gives a directed route from the specified root to every other vertex. Each nonroot has exactly one selected incoming edge and the root has none. There are n−1 edges, no directed cycle, and no vertex disconnected from the root. Reversing every edge would instead describe an in-arborescence with routes toward the root.

An undirected minimum spanning tree ignores direction and can choose edges that cannot be followed from the root. Even selecting the cheapest incoming edge for every nonroot is insufficient because those edges can form a cycle. The calculator checks both the parent structure and root reachability before comparing total costs.

Resolve the cycle in the default directed graph

The edges are 0→1 cost 3, 0→2 cost 5, 1→2 cost 1 and 2→1 cost 1, with root 0. The locally cheapest incoming choices are 2→1 and 1→2, costing 2 but forming a cycle that the root cannot enter through selected edges. They are not a valid spanning out-arborescence.

Choosing 0→1 and 1→2 costs 4 and reaches both vertices. The alternative 0→2 with 2→1 costs 6, while choosing both root edges costs 8. Thus 4 is the minimum. If edge 1→2 is removed, the cheapest valid structure changes; it cannot be recovered by treating that missing direction as an undirected connection.

Interpret unreachable and resource-limited outcomes differently

A vertex not reachable from the root in the full directed input prevents any rooted out-arborescence. The page can identify that structural obstruction before enumeration. A resource-limit error is different: it means the bounded parent-assignment search was too large, not that the graph has no spanning arborescence.

When reachability holds, the exact search enumerates candidate incoming-parent assignments and rejects cyclic choices. The product of candidate counts can grow rapidly even with at most ten vertices, hence the additional 300,000-assignment limit. No incomplete candidate is labeled minimum if that bound is exceeded. Use a dedicated directed-branching algorithm for larger problems.

Model costs and root choice explicitly

Costs may be negative because a valid arborescence contains a fixed number of edges and cannot exploit a negative cycle repeatedly. The objective is the sum of selected costs, not the maximum individual link cost or a shortest route length to every target. A minimum total network can give one vertex a longer root-to-vertex route than a shortest-path tree would.

Choose the root according to the application, such as a broadcast origin, rather than cycling roots until a favored answer appears. The calculator solves for one specified root. Parallel communication links, capacities and redundancy requirements are not part of this simple directed model. The returned edge list is a connectivity certificate, not a fault-tolerant network design.

A few questions, answered

Do edges point toward or away from the root?

Away from it: the result is an out-arborescence reaching every vertex.

Why not choose every cheapest incoming edge?

Those local choices can form a directed cycle disconnected from the root.

Is a minimum arborescence a shortest-path tree?

Not generally. It minimizes total selected-edge cost. A shortest-path tree minimizes root-to-vertex distances, a different objective.

Does a search-limit error mean no spanning route exists?

No. It is inconclusive about optimal cost. Structural unreachability is reported separately from a resource-limited search.

Find your calculator

Start typing to explore the library.