This page is still under construction.

Parts of this page are still being built. What you see may change.

Biking Duck

Time limit2sMemory limit256 MB

Summary
Find the shortest travel time between two map points, walking anywhere but biking only between stations, with free station placement off the map.
Level

Medium7 of 10

Topics
Shortest path, Geometry, Math
Solved
No attempts yet

Problem

Gladstone Gander is walking through Duckburg and has to reach his date with Daisy Duck as fast as he can. If he arrives late, Donald may show up and take his place.

Duckburg recently started a free public bike program. At bike stations all over the city you take a bike, ride it to another bike station, and leave it there. So Gladstone travels in two ways: he walks, or he bikes. Biking is faster, but he takes a bike only at a station and leaves it only at a station. Walking or biking, he moves in a straight line between any two points.

Gladstone carries a map of the rectangular center of Duckburg. His current position and the meeting point with Daisy are both on this map, and the map marks every bike station inside its borders.

More bike stations exist outside the map. Gladstone has endless luck, so you may assume that the moment he walks or rides off the map, a station happens to be exactly where it suits him. Stations outside the map lie anywhere outside it, and their coordinates need not be integers.

Given the map, compute the shortest time Gladstone needs to reach Daisy.

Input

The input consists of:

  • one line with two integers vwalkv_{walk} and vbikev_{bike} (1≤vwalk<vbike≤10001 \le v_{walk} < v_{bike} \le 1000), the walking speed and the biking speed;
  • one line with four integers x1x_1, y1y_1, x2x_2, y2y_2 (−106≤x1<x2≤106-10^6 \le x_1 < x_2 \le 10^6; −106≤y1<y2≤106-10^6 \le y_1 < y_2 \le 10^6), the bounding coordinates of the map of the center;
  • one line with two integers xGx_G and yGy_G, Gladstone's position;
  • one line with two integers xDx_D and yDy_D, Daisy's position;
  • one line with one integer nn (0≤n≤10000 \le n \le 1000), the number of bike stations marked on the map;
  • nn lines with two integers xstationx_{station} and ystationy_{station} each, the coordinates of one marked station.

Every given coordinate lies on the map, that is x1≤x≤x2x_1 \le x \le x_2 and y1≤y≤y2y_1 \le y \le y_2.

Output

Print one line with the shortest time Gladstone needs to reach Daisy, rounded to six digits after the decimal point. Print all six digits.

Examples8

  1. Example 1

    Input
    1 8
    0 0 10 10
    5 1
    5 9
    3
    5 8
    2 2
    9 6
    
    Expected output
    3.000000
    
  2. Example 2

    Input
    5 100
    0 -100000 100000 0
    5 -30000
    40000 -5
    0
    
    Expected output
    501.998750
    
  3. Example 3

    Input
    999 1000
    0 0 1000000 1000000
    500000 500000
    500001 500000
    0
    
    Expected output
    0.001001
    
  4. Example 4

    Input
    1 2
    -5 -5 5 5
    0 0
    0 0
    1
    3 4
    
    Expected output
    0.000000
    
  5. Example 5

    Input
    1 4
    0 0 100 100
    10 10
    90 10
    2
    10 10
    90 10
    
    Expected output
    20.000000
    
  6. Example 6

    Input
    1 5
    0 0 10 10
    0 0
    10 10
    0
    
    Expected output
    2.828427
    
  7. Example 7

    Input
    1 1000
    -1000000 -1000000 1000000 1000000
    0 0
    0 1000
    2
    0 1
    0 999
    
    Expected output
    2.998000
    
  8. Example 8

    Input
    3 60
    -1000000 -1000000 -1 -1
    -999000 -500000
    -2000 -400000
    1
    -500000 -900000
    
    Expected output
    17749.430414