问题描述
一张图,共有m条路,从1走到n,一共可以使k条路的路程为0,求最短路。
思路
去掉的k条路肯定全部在从1到n的某一条路径上,这样走这一条路径才有可能最短。我们可以对最短路分层,即分别求k为0,k为1,k为2……k为k的情况下最短路程。定义最短路时使用二维数组dis[n][k]
,n为结点数,k为分层数。设i为每次求得的最短路结点,kk为所在层,dis为最短路,原点到原点的距离为0,则:
最短路状态转移方程:dis[j][kk]=min(dis[i][kk]+road[i][j],dis[j][kk])
分层状态转移方程:dis[j][kk+1]=min(dis[i][kk],dis[j][kk+1])
Magical Girl Haze
There are NN cities in the country, and MMdirectional roads from uu to v(1\le u, v\le n)v(1≤u,v≤n). Every road has a distance c_ici. Haze is a Magical Girl that lives in City 11, she can choose no more than KK roads and make their distances become 00. Now she wants to go to City NN, please help her calculate the minimum distance.
Input
The first line has one integer T(1 \le T\le 5)T(1≤T≤5), then following TT cases.
For each test case, the first line has three integers N, MN,M and KK.
Then the following MM lines each line has three integers, describe a road, U_i, V_i, C_iUi,Vi,Ci. There might be multiple edges between uu and vv.
It is guaranteed that N \le 100000, M \le 200000, K \le 10N≤100000,M≤200000,K≤10,
0 \le C_i \le 1e90≤Ci≤1e9. There is at least one path between City 11 and City NN.
Output
For each test case, print the minimum distance.
样例输入复制
1 | 1 |
样例输出复制
1 | 3 |
题目来源
1 | #include<bits/stdc++.h> |