PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000082. Đường đua xe dê (Moorio Kart)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đường đua xe dê (Moorio Kart)

Moorio Kart

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN meadows connected by MM undirected roads. Road ii joins meadows AiA_i and BiB_i and has nonnegative integer length DiD_i. The existing network is a forest with no cycles, and every connected component (farm) contains at least two vertices. Consequently, every pair of distinct meadows in the same farm is joined by exactly one simple path.

Suppose there are KK farms. Bessie wants to add exactly KK roads, each of length XX, to create one closed racing loop. The loop must visit each farm exactly once and traverse at least one existing road inside each farm. Within any farm, the loop follows the unique simple path between two distinct selected entry and exit meadows.

Only loops of total length at least YY are interesting. Two loops are different precisely when the sets of adjacent meadow pairs differ after adding the new roads. Reversing the travel direction or choosing a different starting point does not create a new loop. New roads may join different farms; if there is only one farm, its added road closes the loop between two distinct meadows in that farm.

Compute the sum of lengths of all interesting loops, modulo 109+710^9+7. Print neither the number of loops nor their road sets.

Input

The first line contains N,M,X,YN,M,X,Y. Each of the following MM lines contains Ai,Bi,DiA_i,B_i,D_i (vertices are numbered from 11 to NN). The existing roads form a forest in which every vertex is incident to at least one road.

Output

Print one integer: the sum of lengths of all loops of length at least YY, modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 2≤N≤122\le N\le12; 1≤M≤N−11\le M\le N-1; 0≤X,Y≤400\le X,Y\le40; 0≤Di≤200\le D_i\le20; forest with no isolated vertices.

  • Subtask 2 (30 points): 2≤N≤1002\le N\le100; 1≤M≤N−11\le M\le N-1; 0≤X,Y≤2000\le X,Y\le200; 0≤Di≤2000\le D_i\le200; forest with no isolated vertices.

  • Subtask 3 (50 points): 2≤N≤15002\le N\le1500; 1≤M≤N−11\le M\le N-1; 0≤X,Y≤25000\le X,Y\le2500; 0≤Di≤25000\le D_i\le2500; forest with no isolated vertices.

Examples

Example 1

Input

5 3 1 12
1 2 3
2 3 4
4 5 6

Output

54

Explanation

There are two farms. The six loops have lengths 11,11,12,12,15,1511,11,12,12,15,15. The qualifying four sum to 5454.

Example 2

Input

2 1 2 4
1 2 3

Output

5

Explanation

There is one farm and one existing path of length 33; a new road of length 22 closes the only loop, of length 55.