I am about to take the data structure examination. I can see that there is a "broken circle" in the minimal spanning tree. I didn't go into details on the Internet, so I will share my experiences.
The "circle breaking method" is actually a kind of greed.AlgorithmThe only difference is that the prim and krustal algorithms are "adding" edges, which, as the name suggests, are subtraction edges. The idea is as follows:
1. Find a circle in the graph. 2. Delete the edge with the largest weight. 3. Repeat the above operation until there is no circle in the figure.
For undirected graphs, you can do this:
1. Use the topological classification algorithm to find the circle in the graph. Specifically, find the vertices with a moderate value of 1 in the graph (which can be saved in the queue) and delete them (the deletion here is temporary, and these vertices will be restored in the next traversal ), then the inbound degree of the vertex adjacent to it is-1, so that the reciprocating operation will continue until there is no vertex with an inbound degree of 1 in the graph, that is, the degrees of all vertices are equal to 2, then all the remaining edges are in the ring. Of course, if there are no remaining edges, it means that there is no ring and the algorithm ends.
2. The remaining edges are all the edges in the ring. You can delete the biggest right edge.
3. Perform another operation until there is no circle in the figure, that is, all circles have been broken, and the rest is the minimal spanning tree.
It is estimated that this question cannot be obtained, so the algorithm will not be written ~