There are NNN cities in the country, and MMM directional roads from uuu to v(1≤u,v≤n)v(1\le u, v\le n)v(1≤u,v≤n). Every road has a distance cic_ici. Haze is a Magical Girl that lives in City 111, she can choose no more than KKK roads and make their distances become 000. Now she wants to go to City NNN, please help her calculate the minimum distance.
Input
The first line has one integer T(1≤T≤5)T(1 \le T\le 5)T(1≤T≤5), then following TTT cases.
For each test case, the first line has three integers N,MN, MN,M and KKK.
Then the following MMM lines each line has three integers, describe a road, Ui,Vi,CiU_i, V_i, C_iUi,Vi,Ci. There might be multiple edges between uuu and vvv.
It is guaranteed that N≤100000,M≤200000,K≤10N \le 100000, M \le 200000, K \le 10N≤100000,M≤200000,K≤10,
0≤Ci≤1e90 \le C_i \le 1e90≤Ci≤1e9. There is at least one path between City 111 and City NNN.
Output
For each test case, print the minimum distance.
样例输入
1 5 6 1 1 2 2 1 3 4 2 4 3 3 4 1 3 5 6 4 5 2
样例输出
3
AC代码
//#include<bits/stdc++.h>
#define _CRT_SBCURE_NO_DEPRECATE
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
//#define UP(i,x,y) for(int i=x;i<=y;i++)
//#define DOWN(i,x,y) for(int i=x;i>=y;i--)
#define sdddd(x,y,z,k) scanf("%d%d%d%d", &x, &y, &z, &k)
#define sddd(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define sdd(x,y) scanf("%d%d", &x, &y)
#define sd(x) scanf("%d", &x)
#define mp make_pair
#define pb push_back
#define lson k<<1
#define rson k<<1|1
#define mid (1+r)/2
#define ms(x, y) memset(x, y, sizeof x)
#define MOD 142857
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 201000;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
int n, m, t, k;
struct edge
{
int u, v, c;
int next;
};
struct node
{
int v, cost;
node(int v, int c):v(v),cost(c){}
friend bool operator<(node a, node b)
{
return a.cost > b.cost;
}
};
edge G[maxn*100];
int h[maxn*5];
int len;
int d[maxn*5];
void add(int u, int v, int c)
{
G[len].u = u;
G[len].v = v;
G[len].c = c;
G[len].next = h[u];
h[u] = len++;
}
void init()
{
fill(h, h+maxn*5, -1);
len = 0;
}
void dij()
{
fill(d, d+maxn*5, INF);
d[1] = 0;
priority_queue<node> pque;
pque.push(node(1,0));
while(pque.size())
{
node p = pque.top();pque.pop();
int u = p.v;
if(d[u] < p.cost) continue;
for(int i = h[u]; i!=-1; i = G[i].next)
{
edge e = G[i];
if(d[e.v] > d[u]+e.c)
{
d[e.v] = d[u]+e.c;
pque.push(node(e.v, d[e.v]));
}
}
}
}
int main()
{
//freopen("out.txt", "w", stdout);
sd(t);
while(t--)
{
init();
sddd(n, m, k);
int ta, tb, tc;
for(int i = 0; i < m; i++)
{
sddd(ta, tb, tc);
add(ta,tb,tc);
for(int j = 1; j <= k; j++)
{
add(ta+j*n, tb+j*n, tc);
}
}
for(int i = 1; i <= k; i++)
{
for(int j = 1; j <= n; j++)
{
for(int x = h[j]; x!=-1; x = G[x].next)
{
edge e = G[x];
add(e.u, e.v+i*n, 0);
}
}
}
dij();
int ans = INF;
for(int i = 0; i <=k; i++)
{
ans = min(ans, d[n+i*n]);
}
printf("%d\n", ans);
}
return 0;
}