Kart Rider
Time limit1sMemory limit512 MB
Find the minimum time to drive from vertex 1 to vertex N when speed changes by at most 1 per vertex and each edge caps the speed.
- Level
Medium6 of 10
- Topics
- Shortest path, Graph, Heap
- Solved
- No attempts yet
Problem
Kart Rider is a game where the player drives a kart from the starting point along a course and tries to reach the destination as fast as possible.
The map has many shortcuts, so there are several ways to reach the destination.
The map of Kart Rider can be represented as the following undirected weighted graph.

Figure 1
Kart Rider is a racing game, so the player moves at a set speed.
The player starts at the starting point with speed 1. Each time the player visits a vertex, including the starting point, the speed can be increased by 1, decreased by 1, or kept the same. Right after the start, the player can also increase the speed at the starting point.
The speed cannot drop below 1.
An edge between two vertices is a road. Each edge has a length and a speed limit.
Crossing an edge takes the length divided by the speed.
Some sections of the course are hard, and driving fast there can cause a crash into a wall. An edge cannot be used while the player's speed is above that edge's speed limit.
Given the map, find the minimum time needed to travel from the starting point to the destination.
Input
The first line contains the number of vertices and the number of edges , in that order. (, )
Each of the next lines contains four integers describing one edge.
The two vertices and connected by the edge, the length of the edge, and the speed limit are given in that order. (, , )
Vertex 1 is the starting point, and vertex is the destination.
The given graph always has a path from the starting point to the destination.
Output
Print the minimum time needed to travel from the starting point to the destination.
The output must be rounded to exactly 9 digits after the decimal point.
Hint
Using a floating-point type such as double or long double to print the answer can give a wrong result because of the limits on significant digits.