Travel Tax
Time limit2sMemory limit256 MB
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 cities connected by bidirectional roads. A path along the roads exists between any two cities. The president of Byteland is short exactly 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 . Two ways are considered different if there is a road whose toll differs between the two ways. Output the answer modulo .
Input
The first line contains two integers and (), the number of cities in Byteland and the required sum of money. The next lines each contain four numbers , , , (, ), meaning that there is a road between cities and on which a toll from to currency units inclusive can be imposed.
Output
Output a single number: the answer to the problem modulo .