#P7388. Fences

    ID: 6244 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>2023“钉耙编程”中国大学生算法设计超级联赛(10)

Fences

Problem Description

A village consists of $n$ buildings. Each building can be represented as a point on a two-dimensional plane. The coordinates of building $i$ are $(x_i,y_i)$.

The villagers want to put up fences around the village with the following requirements:

- Fences must form a simple polygon;
- Every building is in the polygon (including borders);
- Building $k$, as the entrance of the village, must lie on the fences.

Find the minimum total length of fences required to form a valid polygon.

Input

The first line contains a single integer $T$ ($1\le T\le 10^4$), denoting the number of test cases.

For each test case, the first line contains two integers $n, k$ ($3\le n\le 2\times 10^5$, $1\le k\le n$), denoting the number of buildings and the entrance.

Each of the following $n$ lines contains two integers $x_i,y_i$ ($|x_i|,|y_i|\le 10^6$), denoting the coordinates of building $i$.

For each test case, it is guaranteed that the given points are distinct, and there are at least three points that are not collinear.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

Output

For each test case, output one real number in a single line denoting the minimum total length of fences. (rounding to $3$ decimal places)

1 5 3 0 0 0 2 1 1 2 0 2 2
8.828