{"id":171,"date":"2026-11-13T12:33:29","date_gmt":"2026-11-13T04:33:29","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-edmonds-finds-a-minimum-arborescence\/"},"modified":"2026-11-13T21:51:45","modified_gmt":"2026-11-13T13:51:45","slug":"how-edmonds-finds-a-minimum-arborescence","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-edmonds-finds-a-minimum-arborescence\/","title":{"rendered":"How Edmonds finds a minimum arborescence"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Edmonds&#8217; branching algorithm<\/strong>, also called <strong>Chu-Liu\/Edmonds<\/strong>, 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 <strong>O(VE)<\/strong>.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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&#8217;s own selected edges pay for the rest, so an outside edge into a cycle vertex can be charged the difference above that vertex&#8217;s selected edge.<\/p>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>If the current graph has one vertex, return the empty set of edges.<\/li>\n<li>For every vertex other than the root, choose a cheapest incoming edge. If some vertex has no incoming edge, no arborescence exists.<\/li>\n<li>If the chosen edges contain no cycle, return them. They form an arborescence.<\/li>\n<li>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.<\/li>\n<li>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.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">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|\u22121 edges of minimum total cost under the in-degree constraint.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when a cycle of greedy edges is left uncontracted<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Return the cheapest incoming edge at each vertex even if they cycle<\/td>\n<td>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.<\/td>\n<\/tr>\n<tr>\n<td>Subtract nothing when an outside edge enters the cycle<\/td>\n<td>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.<\/td>\n<\/tr>\n<tr>\n<td>Run Prim on the underlying undirected graph<\/td>\n<td>The undirected tree can use an edge in the wrong direction and can prefer an edge the arborescence is not allowed to use.<\/td>\n<\/tr>\n<tr>\n<td>Choose a cheapest outgoing edge instead of incoming, for an in-branching<\/td>\n<td>The in-degree constraint is on the head. Outgoing selection builds the opposite orientation and needs the reversed graph.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">Undirected minimum spanning trees belong to Kruskal, Prim, or Bor\u016fvka. Shortest paths from the root belong to Dijkstra or Bellman-Ford. Edmonds&#8217; branching is the directed spanning-tree algorithm.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment picks the cheapest incoming edge at every vertex other than the root, contracts a cycle, and subtracts the cycle edge&#8217;s cost from edges that enter the cycle. Expanding the cycle drops the edge that the outside winner replaces. The arborescence costs <code>7<\/code>.<\/p>\n\n<pre><code class=\"language-python\">edges = [(0, 1, 5), (0, 2, 4), (1, 2, 1), (2, 1, 1), (1, 3, 3), (2, 3, 2)]\n\ndef edmonds(n, edges, root=0):\n    def solve(verts, edgelist, root):\n        verts = list(verts)\n        if len(verts) == 1:\n            return []\n        best = {}\n        for u, v, w in edgelist:\n            if u == v or v == root or u not in verts or v not in verts:\n                continue\n            if v not in best or w &lt; best[v][2]:\n                best[v] = (u, v, w)\n        if len(best) != len(verts) - 1:\n            return None\n        chosen = list(best.values())\n        state = {v: 0 for v in verts}\n        cycle = None\n        for start in verts:\n            if start == root or state[start]:\n                continue\n            trail = []\n            u = start\n            while u != root and state.get(u, 1) == 0 and u in best:\n                state[u] = 1\n                trail.append(u)\n                u = best[u][0]\n                if u in trail:\n                    cycle = trail[trail.index(u):]\n                    break\n            if cycle:\n                break\n            for v in trail:\n                state[v] = 2\n        if not cycle:\n            return chosen\n        cset = set(cycle)\n        contracted = []\n        for u, v, w in edgelist:\n            nu, nv, nw = u, v, w\n            if v in cset and u not in cset:\n                nw = w - best[v][2]\n                nv = &quot;C&quot;\n            elif u in cset and v not in cset:\n                nu = &quot;C&quot;\n            elif u in cset and v in cset:\n                continue\n            if nu != nv:\n                contracted.append((nu, nv, nw))\n        new_verts = [v for v in verts if v not in cset] + [&quot;C&quot;]\n        new_root = &quot;C&quot; if root in cset else root\n        inner = solve(new_verts, contracted, new_root)\n        if inner is None:\n            return None\n        entering = None\n        for u, v, w in inner:\n            if v == &quot;C&quot;:\n                # recover the vertex whose reduced cost produced w\n                for src, dst, raw in edgelist:\n                    if src == u and dst in cset and raw - best[dst][2] == w:\n                        entering = dst\n                        break\n        result = []\n        for u, v, w in inner:\n            if v == &quot;C&quot;:\n                for src, dst, raw in edgelist:\n                    if src == u and dst == entering and raw - best[dst][2] == w:\n                        result.append((src, dst, raw))\n                        break\n            elif u == &quot;C&quot;:\n                for src, dst, raw in edgelist:\n                    if src in cset and dst == v and raw == w:\n                        result.append((src, dst, raw))\n                        break\n            else:\n                result.append((u, v, w))\n        for v in cycle:\n            if v != entering:\n                result.append(best[v])\n        return result\n\n    picked = solve(range(n), edges, root)\n    return None if picked is None else sum(w for _, _, w in picked)\n\ncost = edmonds(4, edges)\nchosen = [(0, 2, 4), (2, 1, 1), (2, 3, 2)]\nassert cost == sum(w for _, _, w in chosen) == 7\nprint(cost)\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Edmonds&#8217; 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&#8217;s algorithm is the undirected version and does not orient the edges.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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. <strong>Edmonds&#8217; branching algorithm finds a minimum directed spanning tree by contracting cycles of cheapest incoming edges and expanding them with one edge removed.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: Edmonds&#8217; 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&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,32],"tags":[],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-graphs"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=171"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":570,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/171\/revisions\/570"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}