Reprint: Portal
A simple solution to the problem of secondary short path and sub-niche tree formation
[Secondary short path]
The second shortest path can be regarded as a special case of K-short path problem, and it is more complicated to find the yen algorithm for K-short path, and it can have a more simple method for the short-time path. The following is a solution for finding a short path between two vertices.
We want to find a short path between the vertices s to t of a weighted graph (an anisotropic graph with each edge as two opposite), and first we should find the single-source shortest path of S. Traverse the graph to mark the edges that can be on the shortest path and join the set K. The enumeration then deletes each edge in the set K, seeking the shortest path from S to T, and records the path length value each time it is calculated, and the minimum value is the length of the second short path.
Here we think that the second short path length can be equal to the shortest path length, if you want to wait, can also be seen from S to t have more than one shortest path. If we specify a short path from S to t greater than the shortest path length, the answer is the minimum of the shortest path length of s to t that is greater than the original shortest path after each deletion.
To find the shortest path of single source with dijkstra+ heap, the shortest path time complexity is O (nlog (n+m) + M), so the total time complexity is O (nm*log (n+m) + m^2). This estimate is more pessimistic, because in general, the number of edges on the shortest path is much smaller than m, so the actual effect is better than expected.
[sub-niche into a tree]
Analogy to the above-mentioned short path method, it is easy to think of an "enumeration to delete the minimum spanning tree on each edge, and then the minimum spanning tree" of the visual solution. If the prim+ heap is used, the minimum spanning tree time complexity is O (nlog (n+m) + M), the enumeration is removed with O (n) edges, the time complexity is O (n^2log (n+m) + n*m), and when the graph is dense, close to O (n^3). This method is simple and intuitive, but we have a simpler and more efficient O (n^2+m) solution, which is described below.
First, the minimum spanning tree is obtained, and the sum of the recorded weights is minst. The enumeration adds each edge (u,v) that is not on the smallest spanning tree, plus a ring that is bound to form later. Find the second-largest edge of the weighted value on the ring (that is, except (U,V) the most weighted edge), delete it, and calculate the sum of the weights of the current spanning tree. The minimum value of the sum of the spanning tree weights for all enumeration modifications is the sub-niche tree.
When implemented, a simpler approach is to traverse the entire minimum spanning tree from each node I, defining F[j] as the weight of the largest edge on the path from I to J. Traverse the graph to find the value of F[j], and then for the addition of each edge in the smallest spanning tree (i,j), the sum of the new spanning tree weights is Minst + w (i,j)-f[j], and the minimum value is recorded, then the sub-niche becomes a tree.
The time complexity of the algorithm is O (n^2 + M). Because only the smallest spanning tree is used, the simplest prim can be used, and the time complexity is O (n^2). The bottleneck of the algorithm is not to find the minimum spanning tree, while the enumeration plus edge of O (n^2+m) is modified, so it is not necessary to use a better minimum spanning tree algorithm.
[Examples of sub-short paths and sub-niche trees]
Haoi 2005 Route selection problem direct short path.
PKU 3255 roadblocks a slightly special secondary short path, allowing the edges to repeat.
Ural 1416 Confidential to seek the sub-niche into a tree problem,
PKU 1679 The unique MST determines whether the minimum spanning tree is unique.
Resources
- A summary of Amber's graph theory
Byvoid original explanation, reproduced please specify.
Secondary short-circuit and sub-niche into a tree,