Construction Project 2
Time limit2sMemory limit1024 MB
Count station pairs (u, v) where a new L-minute line between them lets the King reach T from S within K minutes.
- Level
Medium6 of 10
- Topics
- Shortest path, Sorting, Binary search
- Solved
- No attempts yet
Problem
There are stations in JOI Kingdom, numbered from to . There are train lines in JOI Kingdom, numbered from to . Train line () connects station and station in both directions, and takes minutes to travel.
As a minister of JOI Kingdom, you decide to build a new train line as follows.
- Choose integers and with . Build a new train line that connects station and station in both directions, and takes minutes to travel. You may choose and even if a train line already connects them.
After the new line is built, the King becomes happy if he can move from station to station within minutes using the train lines. Transfer times and waiting times are not counted.
Count the pairs that make the King happy. There are pairs in total.
Input
The first line contains and .
The second line contains , , , and .
Each of the next lines contains , , and .
Output
Print the number of pairs that make the King happy.
Constraints
- ()
- ()
- ()
- All given values are integers.