-->
当前位置:首页 > 题库

PROGRAMMING:Xiao Xie's project task

Luz5年前 (2021-05-10)题库487
Xiao Xie is an engineer who has just moved to live on a two-dimensional planet. Now he wants to pave a road for a village on the planet * * it is stipulated that the village has n locations (numbered from 1 to n) to pave a road. He only needs to ensure that any two of the N locations can be connected (i.e. connected map) * *, but because he is on a two-dimensional planet, And each location is abstracted as a point in a two-dimensional coordinate system, and the cost of connectivity for any two locations is no longer related to Euclidean distance. Suppose location $$a (x, y) $, location $$B (P, q) $, * *, now it is stipulated that the cost of laying roads between these two locations * * is $$min (| X - P |, | Y - Q |) $, which is a little difficult for the newcomer Xie. Now he gives you the map, can you help him plan * * a minimum cost project, so that any two points of these n locations are connected * *?
###Input format:
The first line outputs an integer n, representing the number of locations (2 < = n < = 100000)
Next, N lines, two integers x and Y in each line. Represents the coordinates (x, y) of the ith village in the two-dimensional coordinate system.
(0 <= x , y <= 1000000)
###Output format:
Output an integer representing the minimum cost of the project.
###Input example:
```in
three
1 1
5 6
2 3
```
###Output example:
```out
four
```
Example explanation:
The first site and the third site lay roads at the cost of min (| 1-2 |, | 1-3 |) = 1;
The second site and the third site lay roads at the cost of min (| 2-5 |, | 3-6 |) = 3;
At this time, the three locations are connected to each other and satisfy the minimum cost;
The total minimum cost is 4< br>





answer:If there is no answer, please comment