eolymp
bolt
Try our new interface for solving problems
Problems

Moorio Kart

Moorio Kart

Bessie and Farmer John enjoy goat kart racing. The idea is very similar to Go-Kart racing that others enjoy, except the karts are pulled by goats and the track is made from nearby farmland. The farmland consists of n meadows and m roads, each connecting a pair of meadows.

Bessie wants to make a course from nearby farms. A farm is a subset of two or more meadows within which every meadow can reach every other meadow along a unique sequence of roads.

The nearby farmland may contain multiple farms. Suppose there are k farms. Bessie would like to make a goat kart loop by connecting all k farms by adding k roads of length x. Each farm should be visited exactly once and at least one road must be traversed inside each farm.

To make the course interesting for racers, the total length of the track should be at least y. Bessie wants to know the sum, over all such interesting tracks, of the total track lengths. A track is different from another if there are two meadows which are adjacent (after adding the roads between farms) in one track but not the other. Please note that only the roads chosen matter, and not the direction the goat karts will travel along those roads.

Input

The first line contains n, m, x and y (1n1500, 1mn1, 0x, y2500). Each of the m following lines describe roads. The lines are of the form: ai bi di, meaning that meadows ai and bi are connected with a road of integer length di (1ai, bin, 0di2500). Each meadow is incident to at least one road, and there are no cycles of roads.

Output

Print a single integer, giving the sum of track lengths over all interesting tracks. As the sum of track lengths can be quite large, print the sum of lengths modulo 109 + 7.

Example

This example has 6 possible tracks

1 --> 2 --> 4 --> 5 --> 1 (length 11)

1 --> 2 --> 5 --> 4 --> 1 (length 11)

2 --> 3 --> 4 --> 5 --> 2 (length 12)

2 --> 3 --> 5 --> 4 --> 2 (length 12)

1 --> 2 --> 3 --> 4 --> 5 --> 1 (length 15)

1 --> 2 --> 3 --> 5 --> 4 --> 1 (length 15)

The answer is 12 + 12 + 15 + 15 = 54, adding up only the tracks where the length is at least 12.

Time limit 1 second
Memory limit 128 MiB
Input example #1
5 3 1 12
1 2 3
2 3 4
4 5 6
Output example #1
54
Source 2019 USACO February, Platinum