Charlie the Cockchafer

Interview

Time limit1sMemory limit128 MB

Summary
Find the fastest route on a 3D segment network where cost combines travel distance and turn angles between consecutive segments.
Level

Medium7 of 10

Topics
Graph, Shortest path, Geometry, Implementation
Solved
No attempts yet

Problem

Charlie knows how to fly. Even so, moving from one point to another is a tedious chore for him, because Charlie is a cockchafer — and it is well known that every cockchafer (do not confuse them with cockroaches) is clumsy and slow. They need time not only to fly along a straight line, but also, and even more so, to make turns. Knowing these limitations, can you help Charlie find the fastest route?

Input

The input consists of several instances and continues until the end of the file.

The first line of each instance contains three integers NN, SS, and TT (1≤N≤10001 \le N \le 1000, 1≤S,T≤10001 \le S, T \le 1000), where NN is the number of straight flight trajectories (called cockridors), SS is Charlie's flying speed in meters per second, and TT is his turning speed in degrees per second.

The second line contains six integers Xf,Yf,Zf,Xt,Yt,ZtX_f, Y_f, Z_f, X_t, Y_t, Z_t (0≤Xf,Yf,Zf,Xt,Yt,Zt≤100000 \le X_f, Y_f, Z_f, X_t, Y_t, Z_t \le 10000), giving the starting point (Xf,Yf,Zf)(X_f, Y_f, Z_f) and the destination (Xt,Yt,Zt)(X_t, Y_t, Z_t).

Each of the next NN lines contains six integers X1,Y1,Z1,X2,Y2,Z2X_1, Y_1, Z_1, X_2, Y_2, Z_2 (0≤X1,Y1,Z1,X2,Y2,Z2≤100000 \le X_1, Y_1, Z_1, X_2, Y_2, Z_2 \le 10000), describing a cockridor: a line segment joining (X1,Y1,Z1)(X_1, Y_1, Z_1) and (X2,Y2,Z2)(X_2, Y_2, Z_2). No interior point of any segment is an endpoint of another segment, and both the start and the destination are endpoints of at least one segment. All coordinates are given in meters.

Output

For each instance, print on its own line the minimum time RR that Charlie needs to travel from the start to the destination, rounded to exactly 4 digits after the decimal point.

Charlie may fly only along whole segments, and every segment may be used in either direction. The time of a route is R=L/S+D/TR = L/S + D/T seconds, where LL is the total length of the traversed segments (in meters) and DD is the total of the turning angles between consecutive segments (in degrees). You may freely choose Charlie's initial and final facing direction, so there is no turning cost before the first segment or after the last one. A path from the start to the destination is guaranteed to exist.

Examples1

  1. Example 1

    Input
    1 3 1
    0 0 0 10 10 10
    0 0 0 10 10 10
    2 3 1
    0 0 0 10 10 10
    0 0 0 0 10 10
    10 10 10 0 10 10
    
    Expected output
    5.7735
    98.0474