#P1366F. Jog Around The Graph

    ID: 3183 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>binary searchdpgeometrygraphs*2700

Jog Around The Graph

Description

You are given a simple weighted connected undirected graph, consisting of nn vertices and mm edges.

A path in the graph of length kk is a sequence of k+1k+1 vertices v1,v2,,vk+1v_1, v_2, \dots, v_{k+1} such that for each ii (1ik)(1 \le i \le k) the edge (vi,vi+1)(v_i, v_{i+1}) is present in the graph. A path from some vertex vv also has vertex v1=vv_1=v. Note that edges and vertices are allowed to be included in the path multiple times.

The weight of the path is the total weight of edges in it.

For each ii from 11 to qq consider a path from vertex 11 of length ii of the maximum weight. What is the sum of weights of these qq paths?

Answer can be quite large, so print it modulo 109+710^9+7.

The first line contains a three integers nn, mm, qq (2n20002 \le n \le 2000; n1m2000n - 1 \le m \le 2000; mq109m \le q \le 10^9) — the number of vertices in the graph, the number of edges in the graph and the number of lengths that should be included in the answer.

Each of the next mm lines contains a description of an edge: three integers vv, uu, ww (1v,un1 \le v, u \le n; 1w1061 \le w \le 10^6) — two vertices vv and uu are connected by an undirected edge with weight ww. The graph contains no loops and no multiple edges. It is guaranteed that the given edges form a connected graph.

Print a single integer — the sum of the weights of the paths from vertex 11 of maximum weights of lengths 1,2,,q1, 2, \dots, q modulo 109+710^9+7.

Input

The first line contains a three integers nn, mm, qq (2n20002 \le n \le 2000; n1m2000n - 1 \le m \le 2000; mq109m \le q \le 10^9) — the number of vertices in the graph, the number of edges in the graph and the number of lengths that should be included in the answer.

Each of the next mm lines contains a description of an edge: three integers vv, uu, ww (1v,un1 \le v, u \le n; 1w1061 \le w \le 10^6) — two vertices vv and uu are connected by an undirected edge with weight ww. The graph contains no loops and no multiple edges. It is guaranteed that the given edges form a connected graph.

Output

Print a single integer — the sum of the weights of the paths from vertex 11 of maximum weights of lengths 1,2,,q1, 2, \dots, q modulo 109+710^9+7.

Sample Input 1

7 8 25
1 2 1
2 3 10
3 4 2
1 5 2
5 6 7
6 4 15
5 3 1
1 7 3

Sample Output 1

4361

Sample Input 2

2 1 5
1 2 4

Sample Output 2

60

Sample Input 3

15 15 23
13 10 12
11 14 12
2 15 5
4 10 8
10 2 4
10 7 5
3 10 1
5 6 11
1 13 8
9 15 4
4 2 9
11 15 1
11 12 14
10 8 12
3 6 11

Sample Output 3

3250

Sample Input 4

5 10 10000000
2 4 798
1 5 824
5 2 558
4 1 288
3 4 1890
3 1 134
2 3 1485
4 5 284
3 5 1025
1 2 649

Sample Output 4

768500592

Note

Here is the graph for the first example:

Some maximum weight paths are:

  • length 11: edges (1,7)(1, 7) — weight 33;
  • length 22: edges (1,2),(2,3)(1, 2), (2, 3) — weight 1+10=111+10=11;
  • length 33: edges (1,5),(5,6),(6,4)(1, 5), (5, 6), (6, 4) — weight 2+7+15=242+7+15=24;
  • length 44: edges (1,5),(5,6),(6,4),(6,4)(1, 5), (5, 6), (6, 4), (6, 4) — weight 2+7+15+15=392+7+15+15=39;
  • \dots

So the answer is the sum of 2525 terms: 3+11+24+39+3+11+24+39+\dots

In the second example the maximum weight paths have weights 44, 88, 1212, 1616 and 2020.