Moorio Kart

숲이 주어질 때 모든 나무를 연결해 사이클을 만들고, 길이가 Y 이상인 모든 사이클의 총 길이 합을 1e9+7로 나눈 나머지를 구한다.

어려움8트리DFS동적 계획법조합론아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

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 NN meadows and MM 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 KK farms. Bessie would like to make a goat kart loop by connecting all KK farms by adding KK roads of length XX. 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 YY. 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.

입력

The first line of input contains NN, MM, XX, and YY where 1N15001 \leq N \leq 1500, 1MN11 \leq M \leq N-1, and 0X,Y25000 \leq X, Y \leq 2500.

Each of the MM following lines describe roads. The lines are of the form: A_iA\_i B_iB\_i D_iD\_i, meaning that meadows A_iA\_i and B_iB\_i are connected with a road of integer length D_iD\_i (1A_i,B_iN1 \leq A\_i, B\_i \leq N, 0D_i25000 \leq D\_i \leq 2500). Each meadow is incident to at least one road, and there are no cycles of roads.

In at least 70% of the test cases, it is also guaranteed that N1000N \leq 1000 and Y1000Y \leq 1000.

출력

Output 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+710^9+7.

힌트

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=5412+12+15+15=54, adding up only the tracks where the length is at least 1212.