Problem:
Problem D: Discrete Speed

Consider car trips in a country where there is no friction.
Cars in this country do not have engines.
Once a car started to move at a speed, it keeps moving at the same speed.
There are acceleration devices on some points on the road,
where a car can increase or decrease its speed by 1.
It can also keep its speed there.
Your job in this problem is to write a program
which determines the route with the shortest time
to travel from a starting city to a goal city.

There are several cities in the country,
and a road network connecting them.
Each city has an acceleration device.
As mentioned above, if a car arrives at a city at a speed v ,
it leaves the city at one of v - 1, v , or v + 1.
The first road leaving the starting city must be run at the speed 1.
Similarly, the last road arriving at the goal city must be run at the speed 1.

The starting city and the goal city are given.
The problem is to find the best route which leads to the goal city
going through several cities on the road network.
When the car arrives at a city, it cannot immediately go back the road
it used to reach the city. No U-turns are allowed.
Except this constraint, one can choose any route on the road network.
It is allowed to visit the same city or use the same road multiple times.
The starting city and the goal city may be visited during the trip.

For each road on the network, its distance and speed limit are given.
A car must run a road at a speed less than or equal to its speed limit.
The time needed to run a road is the distance divided by the speed.
The time needed within cities including that for acceleration or deceleration should be ignored.

Input

The input consists of multiple datasets, each in the following format.

n m

s g

x 1 y 1 d 1 c 1

...

xm ym dm cm

Every input item in a dataset is a non-negative integer.
Input items in the same line are separated by a space.

The first line gives the size of the road network.
n is the number of cities in the network.
You can assume that the number of cities is between 2 and 30, inclusive.
m is the number of roads between cities, which may be zero.

The second line gives the trip.
s is the city index of the starting city.
g is the city index of the goal city.
s is not equal to g .
You can assume that all city indices in a dataset (including the above two)
are between 1 and n , inclusive.

The following m lines give the details of roads between cities.
The i -th road connects two cities with city indices
xi and yi ,
and has a distance di (1 ≤ i ≤ m ).
You can assume that the distance is between 1 and 100, inclusive.
The speed limit of the road is specified by ci .
You can assume that the speed limit is between 1 and 30, inclusive.

No two roads connect the same pair of cities.
A road never connects a city with itself.
Each road can be traveled in both directions.

The last dataset is followed by a line containing two zeros
(separated by a space).

Output

For each dataset in the input, one line should be output as specified below.
An output line should not contain extra characters such as spaces.

If one can travel from the starting city to the goal city,
the time needed for the best route (a route with the shortest time)
should be printed.
The answer should not have an error greater than 0.001.
You may output any number of digits after the decimal point,
provided that the above accuracy condition is satisfied.

If it is impossible to reach the goal city,
the string "unreachable" should be printed.
Note that all the letters of "unreachable" are in lowercase.

Sample 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

Output for the Sample Input

unreachable
4.00000
5.50000
11.25664

Solution in JAVA (judge verdict: Wrong Answer)

import java.util.Scanner;
 
public class Main {
 
    static int start, goal;             // スタート都市、ゴール都市
    static int n_city, m_road;      // 都市の数、道の数
    static int[][] road_dist;           // 道の距離情報
    static int[][] speed_limit;     // 道の制限速度情報
    static double[][][] city;           // ダイクストラ　最短時間保管表
    static boolean[][][] enter;     // ダイクストラ　最短時間確定
    static final int speed_law = 30;
    static double ans2;
    static int[][][] pre;
     
    // ダイクストラアルゴリズム
    static double Dijkstra(){
        // 初期設定。最短時間をMAX値で初期化。
        city = new double[n_city+1][n_city+1][speed_law+1];
        enter = new boolean[n_city+1][n_city+1][speed_law+1];
        pre = new int[n_city+1][n_city+1][speed_law+1];
        for(int i=0;i<=n_city;i++){
            for(int j=0;j<=n_city;j++){
                for(int k=0;k<=speed_law;k++){
                    city[i][j][k] = Double.MAX_VALUE;
                }
            }
        }
        city[start][start][1] = 0;      // スタート→スタートで速度1の場合、所要時間0
        // ループアルゴ(状態遷移を次々と決める)
        //  cf. 状態遷移とは「ある都市→ある都市の移動(速度も含む)」
        while(true){
            // 最短時間表から最も最短時間な状態遷移を探す
            double fast = Double.MAX_VALUE;
            int x, y, z;        // fastのindex
            x = y = z = -1;
            for(int i=1;i<=n_city;i++){
                for(int j=1;j<=n_city;j++){
                    for(int k=1;k<=speed_law;k++){
                        if(!enter[i][j][k]&&city[i][j][k]<fast){     // 確定されてない & 最短時間
                            fast = city[i][j][k];
                            x = i;  y = j;  z = k;      // 設定されるxはstartと同値が既知
                        }
                    }
                }
            }
            // 表において探した最も最短時間な状態遷移が、
            //      スタート→ゴールで速度が1の場合は解が得られる
//            System.out.println("time="+city[x][y][z]);
            if(x==start&&y==goal&&z==1){
            	ans2 = Math.min(ans2, city[x][y][z]);
//                return city[x][y][1];
            }
            // 最短時間の更新が一度もされない→状態遷移がすべて確定してしまった
            //  (ゴールに辿りつける道がない or ゴール時に速度が1とならない)
            else if(x==-1){
                break;
            }
            enter[x][y][z] = true;      // 探した最短時間状態遷移を確定する
//          System.out.println("enter : x="+x+", y="+y+", z="+z+" pre="+pre[x][y][z]+" time="+city[x][y][z]);
            // 確定した状態遷移から移動できる都市を更新しにいく (yからnexの移動)
            for(int nex=1;nex<=n_city;nex++){        // nex = 遷移先(次)
                // 速度3パターン(-1,0,1)、zは元の速度、spdは遷移時の速度
                for(int spd=z-1;spd<=z+1;spd++){
                    // スピード負値、制限速度オーバー、道路がない　場合は除外
                    if(spd<=0||spd>speed_limit[y][nex]||road_dist[y][nex]==Double.MAX_VALUE){
                        continue;
                    }
                    // スタート地点から出る道とゴール地点に到達する道は必ず速度1 (この問題においての超重要点)
                    //  さらには今来た道なら引き返しなのでNG(x->y y->nex(x) ... x=nex=start)
                    //      さらには状態遷移が決定していれば更新の必要性はない
                    if((x==start&&y==start&&z==1&&spd!=1)||y==nex||pre[x][y][z]==nex){
//                      System.out.println("s="+start+" g="+goal+" y="+y+" z="+z+" nex="+nex+" spd="+spd);
                        continue;
                    }
//                  System.out.println("connect : y="+y+", nex="+nex+", spd="+spd);
                    // 時間 = 距離 / 速度
                  if(city[x][nex][spd]>=city[x][y][z] + road_dist[y][nex]*1.0/spd){
                	  city[x][nex][spd] = city[x][y][z] + road_dist[y][nex]*1.0/spd;
                	  pre[x][nex][spd] = y; 
                  }
//                    city[x][nex][spd] = Math.min(city[x][y][z] + road_dist[y][nex]*1.0/spd , city[x][nex][spd]);
                }
            }
        }
//        System.out.println(ans2);
        return -1;
    }
     
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        while(true){
            n_city = stdIn.nextInt();
            m_road = stdIn.nextInt();
            if((n_city|m_road)==0){
                return;
            }
            start = stdIn.nextInt();
            goal = stdIn.nextInt();
            road_dist = new int[n_city+1][n_city+1];
            speed_limit = new int[n_city+1][n_city+1];
            for(int i=0;i<m_road;i++){
                int x = stdIn.nextInt();
                int y = stdIn.nextInt();
                int d = stdIn.nextInt();
                int c = stdIn.nextInt();
                road_dist[x][y] = road_dist[y][x] = d;
                speed_limit[x][y] = speed_limit[y][x] = c;
            }
            ans2 = 10000;
            double ans = Dijkstra();
            if(ans2!=10000){
                System.out.printf("%.5f\n",ans2);
            }
            else{
                System.out.println("unreachable");
            }
        }
    }
}