10.25 exam Summary
Distance from retirementDeathGetting closer and closer.
Circle
In fact, you only need to perform brute force lookup.
Search for the running chart. Pay attention not to let the mage skip the chart repeatedly. Adding more data will solve the problem. Once you find the accessed data, it will prove that it is a loop ....
At first I thought it was complicated and thought there could be a wonderful figure... it turned out to be a simple ring.
Path
In fact, it is the only way to find the path to reduce some of the points that can be selected more... in fact, it is the Tarjan point, and then find the bridge.
Bridge is the only way to go
Then I want to learn the Tarjan... template.
MST
First, use prim to create the minimum spanning tree. Then consider which side of the weight to modify.
The modified edge must be selected, so we only need to find the vertex A at both ends of the edge; B in the path on the minimum generation tree, and then delete the path.
You can obtain the answer with the largest edge weight in the path.
Time Complexity \ [O (N ^ 2) \]
Final
In my opinion, my ability is the brute force Dijkstra, and the final result seems to be a string burst of space. In fact, the best thing is that the record path is the best.
This question is thoughtful and interesting. All three algorithms are worth writing.
Use Dijkstra + heap to implement the algorithm. The main problem is how to determine the Lexicographic Order of two paths.
Stupid method: If it is two strings, you can use binary + hash to intercept the same prefix. Then, you can see which character is better for the next character. But now all strings are paths, so we can't divide them into two parts. We need to multiply them (similar to LCA, we need to first convert the length of the two strings into equal ones ). It seems that the time complexity is not good, and it is not easy to write.
Clever method: note that the Dijkstra algorithm ensures that the Lexicographic Order is incremental, so every time you need to update the path of a vertex, we only need to compare the last character (if the previous string is equal, it will be compared; otherwise, it does not need to be updated ). Updates in the heap are similar. If the first character is equal, the last character is compared; otherwise, the last character is worse. Time Complexity \ [O (N + mlog N) \]. It's easy to write.
10.25 exam Summary