Problem Description
You have a directed weighted graph with n vertexes and m edges. The value of a path is the sum of the weight of the edges you passed. Note that you can pass any edge any times and every time you pass it you will gain the weight.
Now there are q queries that you need to answer. Each of the queries is about the k-th minimum value of all the paths.
Input
The input consists of multiple test cases, starting with an integer t (1≤t≤100), denoting the number of the test cases.
The first line of each test case contains three positive integers n,m,q. (1≤n,m,q≤5∗104)
Each of the next m lines contains three integers ui,vi,wi, indicating that the i−th edge is from ui to vi and weighted wi.(1≤ui,vi≤n,1≤wi≤109)
Each of the next q lines contains one integer k as mentioned above.(1≤k≤5∗104)
It's guaranteed that Σn ,Σm, Σq,Σmax(k)≤2.5∗105 and max(k) won't exceed the number of paths in the graph.
Output
For each query, print one integer indicates the answer in line.
Sample Input
1 2 2 2 1 2 1 2 1 2 3 4
Sample Output
3 3
Hint
1->2 value :1 2->1 value: 2 1-> 2-> 1 value: 3 2-> 1-> 2 value: 3
Source
2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛
Recommend
liuyiding | We have carefully selected several similar problems for you: 6724 6723 6722 6721 6720
题意:给你一个图,求第k小路径
思路:把每个点连的边从小到大排下序,然后将每个点最小的边放到优先队列,然后每次对最小的边弹出后进行扩展,扩展有两个方向,它要么再往后连它邻接一条最短的边,要么将这条换成父节点邻接的更大一点的边
#include
#include
#include
#include
#include