Discrete Speed

Interview

Time limit8sMemory limit128 MB

Summary
Find the fastest route from a start to a goal city where a car enters each road at an integer speed, changes speed by at most 1 per city, starts and ends at speed 1, and cannot U-turn.
Level

Medium7 of 10

Topics
Graph, Shortest path, Dynamic programming, DFS
Solved
No attempts yet

Problem

Consider car trips in a country that has no friction. The cars here have no engine: once a car starts moving at some speed, it keeps moving at exactly that speed. At certain points along the roads there are acceleration devices that let a car increase or decrease its speed by 11, or keep it unchanged. Your task is to find the route that takes the least time to travel from a start city to a goal city.

The country has several cities connected by a road network, and every city has an acceleration device. Thus, if a car enters a city at speed vv, it leaves that city at speed v−1v-1, vv, or v+1v+1. The very first road leaving the start city must be driven at speed 11, and likewise the very last road entering the goal city must be driven at speed 11.

When the car reaches a city it may not immediately turn back onto the road it just used to get there (no U-turns are allowed). Apart from that, any route through the network is allowed: the same city may be visited more than once, the same road may be used more than once, and the start and goal cities may be passed through during the trip.

Each road has a distance and a speed limit. A car must drive a road at a speed no greater than that road's speed limit, and the speed is always a positive integer. The time to drive a road equals its distance divided by the speed used. The time spent inside cities (including accelerating or decelerating) is ignored.

Input

The input consists of multiple datasets. Each dataset has the following format.

n m
s g
x1 y1 d1 c1
...
xm ym dm cm

Every value is a non-negative integer, and values on the same line are separated by a single space.

The first line gives the size of the road network. nn is the number of cities, with 2≤n≤302 \le n \le 30. mm is the number of roads, which may be 00.

The second line describes the trip. ss is the index of the start city and gg is the index of the goal city, with s≠gs \ne g. Every city index in a dataset lies between 11 and nn inclusive.

Each of the next mm lines describes one road. Road ii connects cities xix_i and yiy_i, has distance did_i (1≤di≤1001 \le d_i \le 100), and has speed limit cic_i (1≤ci≤301 \le c_i \le 30). No two roads connect the same pair of cities, no road connects a city to itself, and every road can be driven in both directions.

The end of the input is a line containing two zeros separated by a space.

Output

For each dataset, print exactly one line.

If the goal city can be reached from the start city, print the time of the fastest route, rounded to exactly five digits after the decimal point (round half up). Otherwise, print the string unreachable in all lowercase.

Do not print any extra characters such as trailing spaces.

Examples4

  1. Example 1

    Input
    2 0
    1 2
    5 4
    1 5
    1 2 1 1
    2 3 2 2
    3 4 2 2
    4 5 1 1
    6 6
    1 6
    1 2 2 1
    2 3 2 1
    3 6 2 1
    1 4 2 30
    4 5 3 30
    5 6 2 30
    6 7
    1 6
    1 2 1 30
    2 3 1 30
    3 1 1 30
    3 4 100 30
    4 5 1 30
    5 6 1 30
    6 4 1 30
    0 0
    
    Expected output
    unreachable
    4.00000
    5.50000
    11.25664
    
  2. Example 2

    Input
    2 1
    1 2
    1 2 7 5
    0 0
    
    Expected output
    7.00000
    
  3. Example 3

    Input
    4 3
    1 4
    1 2 4 3
    2 3 4 3
    3 4 4 3
    0 0
    
    Expected output
    10.00000
    
  4. Example 4

    Input
    2 1
    1 2
    1 2 10 1
    3 3
    1 3
    1 2 2 5
    2 3 2 5
    1 3 3 5
    0 0
    
    Expected output
    10.00000
    3.00000