This page is still under construction.

Parts of this page are still being built. What you see may change.

Travel Tax

Time limit2sMemory limit256 MB

Summary
In a tree of n cities, each road has a toll range [l, r]; count assignments of tolls whose total weighted income (each road weighted by how many shortest paths cross it) equals m, modulo 1e9+7.
Level

Hard8 of 10

Topics
Tree, Combinatorics, Dynamic programming, Math
Solved
No attempts yet

Problem

Byteland consists of nn cities connected by n−1n - 1 bidirectional roads. A path along the roads exists between any two cities. The president of Byteland is short exactly mm Bytelandian currency units to fulfill all his campaign promises. To raise the needed sum, he decided to introduce a toll on travel along the roads.

After a special commission's work, for each road the minimum and maximum amounts of money that the residents of Byteland are willing to pay to use that road were determined. A survey also revealed that this year exactly one person from each city of Byteland plans to travel to each other city of Byteland.

Every resident traveling from one city to another always chooses the shortest route and follows it. When passing along a road, the resident pays the tax set by the president.

The president of Byteland wonders how many different ways there are to set the tolls on the roads so that the total income is exactly mm. Two ways are considered different if there is a road whose toll differs between the two ways. Output the answer modulo 109+710^9 + 7.

Input

The first line contains two integers nn and mm (1≤n,m≤5⋅1051 \le n, m \le 5 \cdot 10^5), the number of cities in Byteland and the required sum of money. The next n−1n - 1 lines each contain four numbers aia_i, bib_i, lil_i, rir_i (1≤ai,bi≤n1 \le a_i, b_i \le n, 1≤li≤ri≤5⋅1051 \le l_i \le r_i \le 5 \cdot 10^5), meaning that there is a road between cities aia_i and bib_i on which a toll from lil_i to rir_i currency units inclusive can be imposed.

Output

Output a single number: the answer to the problem modulo 109+710^9 + 7.

Examples1

  1. Example 1

    Input
    6 152
    1 2 3 4
    2 3 1 2
    2 4 3 5
    4 5 1 1
    4 6 2 2
    
    Expected output
    2