Driver's Dilemma
InterviewTime limit1sMemory limit1024 MB
Find the smallest maximum discomfort for a drive from district 1 to N within time T, where lowering a road's discomfort to D costs extra travel time.
- Level
Medium6 of 10
- Topics
- Graph, Shortest path, Binary search
- Solved
- No attempts yet
Problem
A meeting was suddenly scheduled for an officer who had no plans. The officer's driver immediately opened a map to find the location of the meeting room.
The map has districts and roads connecting them in both directions. Each road has a travel time and a discomfort value. The driver starts in district , and the meeting room is in district .
The meeting is away, so the driver must reach the meeting room within time . The officer does paperwork in the car, so the driver must drive as smoothly as possible. The travel time to the meeting room is the sum of the travel times of the roads used. The discomfort the officer feels is the maximum discomfort among the roads used.
The driver can choose any road and lower its discomfort by by increasing its travel time by , where . Discomfort cannot go below . Driving too slowly to lower discomfort may cause the driver to miss the deadline, while driving at normal speed keeps discomfort high.
Find the minimum discomfort the officer feels when reaching the meeting room within time .
Input
The first line contains , , and separated by spaces. (, , )
From the second line to the -th line, the -th line contains the two districts and that road connects, followed by its travel time and discomfort , separated by spaces. (, , , )
Output
Print the minimum discomfort the officer feels when reaching the meeting room within time .
If the meeting room cannot be reached within time in any way, print .