QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 32 MB 총점: 100

#17057. 太空旅行

통계

第四伟大而繁荣的人类帝国正在开发一个连接其所有行星的跨管道隧道网络。该帝国由 $N$ 颗行星组成,它们表示为三维空间中的点。在行星 $A$ 和 $B$ 之间建立跨管道隧道的代价为:

$$TunnelCost[A,B] = \min( |x_A-x_B|, |y_A-y_B|, |z_A-z_B| )$$

其中 $(x_A, y_A, z_A)$ 是行星 $A$ 的三维坐标,$(x_B, y_B, z_B)$ 是行星 $B$ 的坐标。帝国需要建造恰好 $N - 1$ 条隧道,以便将所有行星完全连接起来(无论是通过直接连接还是通过链式连接)。你需要计算出成功完成该项目的最低可能代价。

输入格式

输入的第一行包含一个整数 $N$ ($1 \le N \le 100\,000$),表示行星的数量。

接下来的 $N$ 行,每行包含恰好 $3$ 个整数。所有整数都在 $-10^9$ 到 $10^9$ 之间(含端点)。每行依次包含一颗行星的 $x$、$y$ 和 $z$ 坐标。

保证没有两颗行星会占用空间中的同一个点。

输出格式

输出的第一行也是唯一一行,应包含建立隧道网络的最小代价。

样例

输入样例 1

2
1 5 10
7 8 2

输出样例 1

3

输入样例 2

3
-1 -1 -1
5 5 5
10 10 10

输出样例 2

11

输入样例 3

5
11 -15 -15
14 -5 -15
-1 -1 -5
10 -4 -1
19 -4 19

输出样例 3

4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.