All Blue
Sanjindra is close to finding the All Blue and fulfilling their dream! However, there remains yet one obstacle in their path: a treacherous portion of the Calm Belt filled with evil sea monsters. Sanjindra knows that their ship, the Thousand Sunny, is strong and can take less than k points of damage before that it will sink.
The portion of the Calm Belt can be modelled as a graph with n nodes, connected by m routes. Each route has a two endpoints (ai and bi), a distance (wi), and the damage the sea monsters will do (di).
As Namindra, the navigator of the ship, it is your job to find the shortest route from nodes x to y which takes less than k points of damage. Can you help Sanjindra with this task?
Input Format
The first line of input will consist of 3 integers, k n m. Each of the next lines will consist of 4 integers ai bi wi and di, as described in the description. Finally, the last line will contain two integers x and y, the point Sanjindra starts and wants to end.
Output Format
The output should consist of a single integer, the minimum length of the path if it is possible, or 1 if it is not.
Constraints
1≤k≤200
2≤n≤2000
n≤m≤10000
0≤ai,bi≤n−1
1≤wi≤1e5
0≤ci≤200
Sample Input
10 4 7
0 1 4 4
0 2 7 2
2 0 8 1
2 1 2 2
3 1 1 6
2 3 1 1
0 3 6 12
0 3
Sample Output
7
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.