cswork / OA打开练习工作台

NutanixOA #3

Min Cost to Connect All Points

估计中等可在线判题

考点(AI 标注)生成树

The cost of connecting two points is their Manhattan distance. Find the minimum total edge weight that connects all points so that there is exactly one simple path between any two points.

The standard input/output format and any supplementary ranges on this site are as defined in this problem statement.

输入格式

n (1≤n≤1000), followed by n lines of integer coordinates x y (−10^6≤x,y≤10^6); all coordinates are distinct.

输出格式

Output the total weight of the minimum spanning tree.

样例 1

输入:

5
0 0
2 2
3 10
5 2
7 0

输出:

20

样例 2

输入:

3
3 12
-2 5
-4 1

输出:

18

样例 3

输入:

1
4 -2

输出:

0