Source: released examination PDF, bundle pages 9–17, paper pages 1–9. Solutions follow every option of the 17 June 2021 Short Options paper. The fixed-length brachistochrone between equal-height endpoints, shortest-path tree and discrete population dynamics answers explain the domain qualifications needed for the literal printed claims.
For a finite connected graph, a spanning tree contains every graph vertex and is connected and acyclic. A minimum spanning tree minimizes over all such trees. A shortest-path tree rooted at is a spanning tree whose unique -to- graph path has length for every graph vertex . Here the weighted path length is the sum of its edge weights. The two optimizations generally differ, as (b) shows. Connectedness is needed for either spanning-tree object to exist.
For the grid, Kruskal's algorithm examines edges in nondecreasing order of weight and accepts an edge exactly when it joins two different components of the current forest. The weights are encountered in the order
The horizontal and vertical acceptance rules are detailed in the two numbered subanswers. Together they produce
There are horizontal and vertical edges, totaling . Every accepted edge attaches a previously isolated graph vertex to the component already built, so the result is connected and acyclic. The correctness theorem for Kruskal's algorithm, which follows from the minimum spanning tree cut property, proves minimality. Its total cost is
For the tree has one graph vertex, no edges and cost zero. The source's numbered items specify the two edge types; the following subanswers record their contributions to the algorithm.
Figure 1.
Kruskal spanning tree of the weighted grid, with accepted horizontal and vertical edges highlighted
. Details.
Use a triangle with graph vertices and edge weights
Its unique minimum spanning tree is , of cost , because the other two spanning-tree costs are . In this tree the -to- graph path has length , whereas the edge gives length in the original graph. Therefore
Since the minimum spanning tree is unique, none is a shortest-path tree rooted at .
By (i), two simple graph paths with different edge sets have different lengths. In particular two distinct simple graph paths from the fixed root to the same graph vertex have different edge sets, so there is a unique shortest graph path from to each . Positive weights ensure that a shortest walk has no repeated graph vertex: removing a graph cycle strictly reduces its length.
For each , take the final edge of its unique shortest graph path. Every initial segment of a shortest graph path is itself shortest, since replacing it by a shorter one would shorten the whole route. Thus these edges agree with the graph paths' unique predecessors. Following a predecessor strictly decreases , so no predecessor graph cycle is possible, and all graph vertices eventually connect to . They form a shortest-path tree. Every other such tree would have to use the same unique root-to-vertex graph paths, proving
Literal wording qualification. “Any two paths” needs a convention. Reversing an undirected graph path preserves its edge set and length; distinct zero-edge graph paths at different graph vertices also have length zero. Thus the unrestricted statement is false if these count as different graph paths. The proved edge-set assertion, and in particular uniqueness for graph paths with the same ordered endpoints, is exactly what is needed for the deduction. Arbitrary walks are not included.
For Dijkstra's algorithm, initialize and for other vertices, with no predecessor initially. Repeatedly select an unfinalized vertex of least tentative distance, finalize it, and relax each edge : if , replace by that value and set the predecessor of to . Continue until all vertices are finalized. The predecessor edges form the shortest-path tree.
To justify finalization, consider a supposedly shorter route to the next selected vertex. Its first unfinalized vertex is preceded by a finalized one, whose relaxation would already have offered a tentative distance no greater than the length of that route's prefix. Nonnegative remaining lengths would contradict the selected vertex's minimal tentative label. Thus final labels are the true shortest distances. Strictly positive lengths also make predecessors have smaller distances, ruling out predecessor cycles in a graph.
A shortest-path tree rooted at is a spanning tree such that, for every vertex , the unique graph path in has minimum total edge length among all graph paths in . The objective is the sum of the lengths along each route, not the sum of all the tree's edge lengths.
Starting from , the initial tentative distances to are . Finalize next. Its edges improve these to , , and . No subsequent relaxation improves them. Hence one shortest-path tree is
These values follow either by completing Dijkstra's algorithm in the order , or by observing that any internal vertex on a simple route adds to the direct-edge cost: only the internal vertex can reduce it.
All edge lengths are positive, so run the Dijkstra algorithm from every source , retaining distances and a shortest-path tree of its reachable component. Each run takes with a binary heap. The following scans after each run use only additional work.
For a directed graph, inspect every closing edge and consider when is reachable. The tree route from to followed by this edge is a closed walk. Every directed cycle supplies one such upper bound by choosing any of its vertices as ; the shortest route to its predecessor is no longer than the corresponding cycle segment. Positivity lets any repeated portion be removed, so the smallest candidate is the shortest directed-cycle length.
For an undirected graph, do not combine an edge with the distance between its endpoints indiscriminately: that can count traversal of one bridge out and back as a false cycle. Instead inspect only edges absent from the current shortest-path tree, with both endpoints reachable, and consider
The two tree routes and this non-tree edge contain a genuine cycle. If they share a prefix, its cost is counted twice, so that cycle is no longer than the candidate. Every candidate is consequently at least the global shortest-cycle length.
To prove equality is attained, take a shortest cycle and a source on it. If either cycle edge incident to is absent from the tree, its candidate uses a shortest route no longer than the rest of , so it is at most the length of . Otherwise both incident edges are in the tree, and their other endpoints lie in different branches below . Along the remaining segment of , some edge crosses between different branches. Such an edge is not a tree edge. The two distances to its endpoints are bounded by the two corresponding, disjoint segments of from ; their sum plus the crossing edge is at most the length of . Thus some candidate is no greater than the optimum, completing the proof.
Return the smallest finite candidate, or report acyclicity if none exists. The total running time is , as required. The ordinary convention is a simple graph; if parallel edges are allowed, track actual edge identities when excluding tree edges, and treat a self-loop as its own cycle rather than discarding it. This is shortest cycle by repeated shortest-path trees.
In a positive-weight directed graph, run the Dijkstra algorithm from each source and minimize over closing edges. In an undirected graph, minimize only over edges absent from the current shortest-path tree. A tree edge would otherwise give a spurious traversal out and back. A non-tree candidate contains a genuine cycle no longer than its score, even when the two tree routes share a prefix.
For the undirected optimum, choose a shortest cycle and a source on it. If an incident cycle edge is absent from the tree, its candidate is bounded by the cycle length. Otherwise its two neighbours lie in distinct tree branches, and some edge on the remaining cycle segment crosses branches. That edge is non-tree; shortest distances to its endpoints are bounded by the two complementary cycle segments, again giving a candidate no greater than the optimum. Thus the minimum candidate equals the shortest-cycle length. Repeated Dijkstra algorithm runs take running time with a binary heap.
Shortest-path tree 2026-10-25
A shortest-path tree rooted at a source vertex is a spanning tree whose unique tree route from the source to every vertex solves the shortest path problem in the original weighted graph. Dijkstra's algorithm constructs one for a finite connected graph with nonnegative edge lengths, recording a predecessor whenever a distance improves. It need not be a minimum spanning tree: one minimizes each source-route length, the other the total weight of the tree's edges.