Short answer: Edmonds’ branching algorithm, also called Chu-Liu/Edmonds, finds a minimum-cost spanning arborescence of a directed graph: a directed tree in which every vertex except the root has in-degree one and every vertex is reachable from the root. Each vertex selects its cheapest incoming edge. If those edges form no cycle, they are optimal. A cycle is contracted, the costs of edges entering the cycle are reduced by the edge the cycle vertex had chosen, and the algorithm recurses. Expanding the cycle drops one selected edge. A classical implementation is O(VE).
What the problem actually asks
An undirected minimum spanning tree can pick the cheapest safe edge with no thought about direction. A directed spanning tree rooted at r has to point away from r, or toward r if the convention is an in-branching. Greedy selection of the cheapest incoming edge is necessary and not sufficient, because those edges can form a cycle that does not touch the root. The cycle must be entered exactly once. Whichever vertex is the entry, the cycle’s own selected edges pay for the rest, so an outside edge into a cycle vertex can be charged the difference above that vertex’s selected edge.
Contraction makes the cycle a single supervertex and repeats the argument. Expansion stitches the outside edge in and deletes the one selected edge that would give the entry vertex a second parent.
What the algorithm guarantees
If a spanning arborescence exists, the algorithm returns one of minimum total cost. If a vertex other than the root has no incoming edge at any stage, none exists. Time for the textbook contraction is O(VE). Extra memory is the contracted graph. Faster implementations exist and do not change the contraction logic. Costs may be negative. A negative cycle that is not the only way to connect the graph is still handled by the reduction, because the objective is a tree, not a walk that could loop.
The root has no selected incoming edge. Running the algorithm from the wrong root, or on edges that were stored backward, answers a different reachability question and can report that no arborescence exists when one does.
The working steps
- If the current graph has one vertex, return the empty set of edges.
- For every vertex other than the root, choose a cheapest incoming edge. If some vertex has no incoming edge, no arborescence exists.
- If the chosen edges contain no cycle, return them. They form an arborescence.
- Contract each cycle of chosen edges into a supervertex. For an edge from outside the cycle into a cycle vertex v, replace its cost by its cost minus the cost of the chosen edge into v.
- Recurse. Expand by adding the chosen edges of the cycle, except the one that points at the vertex where the outside edge from the recursive solution enters.
The output is a directed spanning tree rooted at a designated root, not an undirected minimum spanning tree and not a shortest-path tree. Kruskal and Prim ignore direction. Dijkstra minimizes path length and need not connect with |V|−1 edges of minimum total cost under the in-degree constraint.
Approaches that look simpler and fail
| Approach | Why it fails when a cycle of greedy edges is left uncontracted |
|---|---|
| Return the cheapest incoming edge at each vertex even if they cycle | A cycle is not an arborescence. The root cannot reach those vertices along the chosen edges, or the in-degrees are wrong once the cycle is oriented as a circuit. |
| Subtract nothing when an outside edge enters the cycle | The recursive cost would rather avoid the cycle than pay a fair entry. The reduction by the discarded cycle edge is what keeps the optimum. |
| Run Prim on the underlying undirected graph | The undirected tree can use an edge in the wrong direction and can prefer an edge the arborescence is not allowed to use. |
| Choose a cheapest outgoing edge instead of incoming, for an in-branching | The in-degree constraint is on the head. Outgoing selection builds the opposite orientation and needs the reversed graph. |
Undirected minimum spanning trees belong to Kruskal, Prim, or Borůvka. Shortest paths from the root belong to Dijkstra or Bellman-Ford. Edmonds’ branching is the directed spanning-tree algorithm.
A working example
This Python fragment picks the cheapest incoming edge at every vertex other than the root, contracts a cycle, and subtracts the cycle edge’s cost from edges that enter the cycle. Expanding the cycle drops the edge that the outside winner replaces. The arborescence costs 7.
edges = [(0, 1, 5), (0, 2, 4), (1, 2, 1), (2, 1, 1), (1, 3, 3), (2, 3, 2)]
def edmonds(n, edges, root=0):
def solve(verts, edgelist, root):
verts = list(verts)
if len(verts) == 1:
return []
best = {}
for u, v, w in edgelist:
if u == v or v == root or u not in verts or v not in verts:
continue
if v not in best or w < best[v][2]:
best[v] = (u, v, w)
if len(best) != len(verts) - 1:
return None
chosen = list(best.values())
state = {v: 0 for v in verts}
cycle = None
for start in verts:
if start == root or state[start]:
continue
trail = []
u = start
while u != root and state.get(u, 1) == 0 and u in best:
state[u] = 1
trail.append(u)
u = best[u][0]
if u in trail:
cycle = trail[trail.index(u):]
break
if cycle:
break
for v in trail:
state[v] = 2
if not cycle:
return chosen
cset = set(cycle)
contracted = []
for u, v, w in edgelist:
nu, nv, nw = u, v, w
if v in cset and u not in cset:
nw = w - best[v][2]
nv = "C"
elif u in cset and v not in cset:
nu = "C"
elif u in cset and v in cset:
continue
if nu != nv:
contracted.append((nu, nv, nw))
new_verts = [v for v in verts if v not in cset] + ["C"]
new_root = "C" if root in cset else root
inner = solve(new_verts, contracted, new_root)
if inner is None:
return None
entering = None
for u, v, w in inner:
if v == "C":
# recover the vertex whose reduced cost produced w
for src, dst, raw in edgelist:
if src == u and dst in cset and raw - best[dst][2] == w:
entering = dst
break
result = []
for u, v, w in inner:
if v == "C":
for src, dst, raw in edgelist:
if src == u and dst == entering and raw - best[dst][2] == w:
result.append((src, dst, raw))
break
elif u == "C":
for src, dst, raw in edgelist:
if src in cset and dst == v and raw == w:
result.append((src, dst, raw))
break
else:
result.append((u, v, w))
for v in cycle:
if v != entering:
result.append(best[v])
return result
picked = solve(range(n), edges, root)
return None if picked is None else sum(w for _, _, w in picked)
cost = edmonds(4, edges)
chosen = [(0, 2, 4), (2, 1, 1), (2, 3, 2)]
assert cost == sum(w for _, _, w in chosen) == 7
print(cost)
Where it is used
Edmonds’ algorithm (Chu-Liu/Edmonds) computes a minimum spanning arborescence: the cheapest directed tree into every node from a root. Telecommunication network design uses that directed tree. Kruskal’s algorithm is the undirected version and does not orient the edges.
When you can drop this algorithm
Drop this algorithm when the graph is undirected. Use Kruskal or Prim. Keep it when a designated root must reach every vertex by directed edges and the total edge cost must be minimum.
Why this stays published
We publish this so a search for the Chu-Liu/Edmonds algorithm returns the cycle contraction and the cost reduction on edges that enter the cycle. Edmonds’ branching algorithm finds a minimum directed spanning tree by contracting cycles of cheapest incoming edges and expanding them with one edge removed.
本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。
