#P7561. [JOISC 2021] 道路の建設案 (Road Construction) (Day2)
[JOISC 2021] 道路の建設案 (Road Construction) (Day2)
Background
10s, 2048M.
Problem Description
The Kingdom of JOI is a two-dimensional plane. There are towns in the kingdom, numbered , and the coordinates of town are .
In the Kingdom of JOI, there is a plan to build roads connecting two towns (hereinafter referred to as a “road construction project”). There will be roads. Connecting two different towns and costs yen. If there is already a road connecting and , then there is no need and it is not allowed to build another road connecting and , because they are the same.
You need to manage this “road construction project”. To calculate the costs, you need to figure out the costs required to connect some towns. Among these possible roads, you want to know the costs of the cheapest roads.
Given the coordinates of the towns and , compute how much money is needed for the cheapest roads.
Input Format
The input consists of lines.
The first line contains two positive integers . is the number of towns, and the meaning of is described in the Description section.
Each of the next lines contains two integers and (), representing the coordinates of town .
Output Format
Output lines.
On line , output one integer representing the cost in yen of the -th cheapest road.
3 2
-1 0
0 2
0 0
1
2
5 4
1 -1
2 0
-1 0
0 2
0 -2
2
2
3
3
4 6
0 0
1 0
3 0
4 0
1
1
2
3
3
4
10 10
10 -8
7 2
7 -8
-3 -6
-2 1
-8 6
8 -1
2 4
6 -6
2 -1
3
3
4
5
6
6
6
7
7
7
Hint
Sample #1 Explanation
There are possible choices.
- Town town : yen.
- Town town : yen.
- Town town : yen.
Sorting them gives , so the output is and .
This sample satisfies Subtasks .
Sample #2 Explanation
There are possible choices.
After sorting, the costs are .
This sample satisfies Subtasks .
Sample #3 Explanation
This sample satisfies Subtasks .
Sample #4 Explanation
This sample satisfies Subtasks .
Constraints and Notes
This problem uses subtask scoring.
| Subtask | Score Percentage | |||
|---|---|---|---|---|
| / | / | |||
| / | ||||
| / | ||||
| / |
Note: A slash means there is no special restriction.
For of the testdata:
- .
- $1 \le k \le \min(2.5 \times 10^5,\ \dfrac{n\cdot(n-1)}{2}$).
- , and .
- for .
Notes
This problem is translated from The 20th Japanese Olympiad in Informatics 2020/2021 Spring Training Camp - Contest 2 - T2 Japanese statement.
Translated by ChatGPT 5