This page is still under construction.

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

Bounty Hunter Jeong-eun

Time limit1sMemory limit256 MB

Summary
A ship visits every planet sorted by x on an outward and a return monotone leg with minimum total Euclidean length.
Level

Medium7 of 10

Topics
Dynamic programming, Geometry
Solved
No attempts yet

Problem

Jeong-eun is a bounty hunter chasing a criminal. Jeong-eun flies the ship Galchi II and has to visit all NN planets scattered over a two dimensional plane, then return to the starting planet. The starting planet is the one with the smallest xx coordinate. Jeong-eun is poor but extravagant and wants to keep enough money for expensive beef, so the total travel distance has to be as small as possible.

Jeong-eun is also chasing the crime syndicate CTP, and restricts the route to avoid being spotted. From the starting planet to the planet with the largest xx coordinate, the ship moves only in increasing order of xx. Coming back from there to the starting planet, it moves only in decreasing order of xx. The two legs together visit every planet exactly once. The planet with the smallest xx coordinate and the planet with the largest xx coordinate are the turning points shared by both legs, and every other planet belongs to exactly one leg. When N=2N = 2 the route goes from the left planet to the right planet and straight back.

The distance between two planets is the Euclidean distance. Find the shortest total length among the routes that satisfy the rule.

Input

The first line contains the number of test cases TT (1≤T≤1001 \le T \le 100).

The first line of each test case contains the number of planets NN (2≤N≤5122 \le N \le 512). Each of the next NN lines contains the coordinates xx and yy (0≤x,y≤50000 \le x, y \le 5000) of one planet, separated by a space.

All coordinates are integers. Within one test case the xx coordinates are distinct, and the planets are given in increasing order of xx.

Output

For each test case, print the length of the shortest route on its own line.

Round the length at the fourth decimal place and print exactly four digits after the decimal point. Pad with zeros even when the value is an integer, as in 400.0000. The output is compared as an exact string.

Examples2

  1. Example 1

    Input
    2
    5
    0 1
    1 2
    2 0
    3 2
    4 1
    3
    100 1
    200 1
    300 1
    
    Expected output
    9.3006
    400.0000
  2. Example 2

    Input
    1
    2
    0 0
    5000 5000
    
    Expected output
    14142.1356