Return of the Jedi

Time limit1sMemory limit128 MB

Summary
Given up to 10 non-overlapping circular trees in the plane, find the shortest path length around them from start to goal point, then divide by the speed of 200 miles per hour.
Level

Hard8 of 10

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

Problem

Luke Skywalker races through the forest on a speeder bike, trying to outrun a patrol of Imperial scouts on the forest moon of Endor. The moon is covered by dense foliage and a thick forest of ancient, towering trees. The speeder bike is an antigravity vehicle that moves at a constant speed of 200 miles per hour, and Luke wants to reach Princess Leia in the Ewok village as quickly as possible.

Model the forest as a plane containing TT trees. Each tree is a circular obstacle, and Luke may not pass through the interior of any tree, so his route must curve around them. Luke starts at (xluke,yluke)(x_{luke}, y_{luke}) and the Ewok village is at (xewok,yewok)(x_{ewok}, y_{ewok}). Find the shortest possible travel time from Luke's starting position to the Ewok village.

Input

The first line contains five numbers: the integer TT followed by xlukex_{luke}, ylukey_{luke}, xewokx_{ewok}, and yewoky_{ewok}.

Each of the next TT lines describes one tree with three numbers: its center xtreex_{tree}, ytreey_{tree} and its diameter dtreed_{tree}.

TT is an integer that is at most 1010. All coordinates and diameters are real numbers measured in miles. No two trees intersect or touch each other, and neither Luke's start nor the Ewok village lies inside a tree.

Output

Print a single real number: the minimum travel time in seconds, rounded to exactly two decimal places.

Examples4

  1. Example 1

    Input
    2 0.0 0.0 10.0 0.0
    4.0 0.0 1.0
    6.0 0.0 1.0
    
    Expected output
    181.13
    
  2. Example 2

    Input
    0 0 0 10 0
    
    Expected output
    180.00
    
  3. Example 3

    Input
    0 0 0 3 4
    
    Expected output
    90.00
    
  4. Example 4

    Input
    1 0 0 10 0
    5 0 2
    
    Expected output
    183.61