CodeForces 1196F K-th Path

Impressions

Training for two weeks, I felt level is rising, very good. Yesterday CF make up five questions today to update the blog.

This problem is CodeForces1196 last question, a div3 of.

Chinese 题意

To a \ (n-\) points \ (m \) no connected graph of edges, so that all seek the shortest in this figure, the \ (K \) short shortest (switching starts and ends with the calculation one way).

Problem-solving ideas

The official said so solution to a problem -

1196F - K-th Path

The main observation is that you don't need more than m i n ( k , m ) smallest by weight edges (among all edges with the maximum weights you can choose any). Maybe there will be a proof later, but now I ask other participant to write it.

So you sort the initial edges and after that you can construct a graph consisting of no more than 2 m i n ( k , m ) vertices and no more than m i n ( m , k ) edges. You just can build the new graph consisting only on these vertices and edges and run Floyd-Warshall algorithm to find the matrix of shortest paths. Then sort all shorted distances and print the k -th element of this sorted array.

Time complexity: O ( m log m + k 3 ) .

I know that there are other approaches that can solve this problem with greater k , but to make this problem easily this solution is enough.

哈哈

Guess you like

Origin www.cnblogs.com/wawcac-blog/p/11287195.html