Legal path

Accepts: 9
Submissions: 171
Time Limit: 6000/3000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description
Given a directed graph ,every edge has a weight. A legal route is defined as the list of edge, for every edge's weight should at least K greater than last edge's weight,if the last one exist. the length of a legal route is the total weight of the edge on it. We should find the legal path from node $1$ to node $n$ of minimum length.
Input
There is a number \(T\) shows there are T test cases below. ($T \leq 10$) For each test case , the first line contains three integers $n , m , K$, $n , m$ means the number of nodes and the number of edges on the graph. In following there are $m$ lines. Each line has three integer $x , y , z$. indicate that there is an edge frome $x$ to $y$ weighted $z$. $2 \leq n \leq 100,000$ $0 \leq m \leq 200,000$ $1 \leq K,z \leq 1,000,000,000$ $1 \leq x,y \leq n$
Output
For each case ,if there is no legal path from $1$ to $n$, output -1 ,otherwise output the answer.
Sample Input
3
3 2 1
1 2 1
2 3 2
3 2 1
1 2 2
2 3 1
4 6 2
1 2 1
1 2 2
2 3 3
1 3 5
2 4 2
3 4 7
Sample Output
3
-1
11