Villages: Landcircles
题号:NC239330
时间限制:C/C++/Rust/Pascal 10秒,其他语言20秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
Special Judge, 64bit IO Format: %lld

题目描述

Because of the great success of Villages: Landlines, its development team, NIO Tech, decides to develop its sequel. They call it Villages: Landcircles. In the sequel, the development team decides to use a new power system.

They change the power system from one dimension to two dimensions. In the new power system, initially there are several power stations and buildings. The goal of the game is to make every power stations and buildings connected together in the power system, forming a connected graph. Players can build some power towers and wires in the game, which are the tools to connect power stations and buildings.

Power stations or buildings can connect to power towers without wires, while power towers must connect to each other by wires. What's more, power stations and buildings can't connect to each other directly, they must connect through power towers.

Assuming that the coordinates of a building are (x_i,y_i) and its receiving radius is r_i, all the power towers whose distance from the building is no greater than r_i are directly connected to it without wires. That is to say, for the power tower located at (x,y), it is directly connected to the building at (x_i,y_i) without wires if and only if . Similarly, assuming that the power supply radius of a power station is r_s, all the power towers whose distance from the power station is no more than r_s are directly connected to it without wires. Supposing that the coordinates of two power towers are (x_A,y_A) and (x_B,y_B), players can connect them with the wire, and the length of wire required is . A power tower can be connected to any number (possibly zero) of power towers, buildings and power stations.

In order to make the game more friendly to the rookies, Mocha, a member of NIO Tech, decides to develop the power distribution recommendation function. In the case of using any number of power towers, players can choose exactly one power station and several buildings to get an optimal power supply scheme, which uses the shortest total length of wires to complete the power system. However, Mocha is not sure whether her scheme is correct, so she needs your help to calculate the total length of wires used in the optimal scheme to determine the correctness of her scheme.

输入描述:

The first line contains a single integer T () — the number of the test cases. For each test case:

The first line contains a single integer n ().

The second line contains three integers x_s,y_s,r_s () — the coordinates of the power station and its power supply radius.

The i-th line of the next n-1 lines contains three integers x_i,y_i,r_i () — the coordinates of the i-th building and its receiving radius.

It is guaranteed that for any two distinct buildings i and j, holds. Similarly, it is guaranteed that for any building i, holds.

It is guaranteed that there are no more than 10 test cases with in a test.

输出描述:

For each test cases, print a real number in a single line, denoting the total length of wires used in the optimal scheme. Your answer will be considered correct if its relative or absolute error does not exceed .
示例1

输入

复制
3
2
0 0 1
2 2 1
3
0 0 10
20 -1 1
-20 -1 1
3
0 0 1
1000 -1000 1
-1000 -1000 1

输出

复制
0.82842712
18.04996879
2729.05080757