[USACO22FEB] Moo Network G
题意翻译
## 题目描述
农夫约翰有 $N$ 头牛($1\le N\le10^5$) 它们在农场里分布的极其的远,因此希望你建立一个通讯网络,便于它们更容易地交换电子短信(当然,这些短信都包含 `moo` 的变形体,即数字)
第 $i$ 头牛位于位置 $(x_i,y_i)$ 其中 $0\le x\le 10^6$, $0\le y\le 10$. 在牛 $i$ 与牛 $j$ 之间建立通信链路的成本是它们之间的欧几里德距离的平方,即 $(x_i-x_j)^2+(y_i-y_j)^2$
请聪明的你构建一个所有奶牛都能交流的最低成本的通信网络。如果两头奶牛通过一条链接直接连接或者它们的信息可以沿着一条链接传播,那么认为他们可以通信。
#### 注意 此问题时间限制为4秒
## 输入格式
第一行输入为 $N$,接下来 $N$ 行分别描述奶牛的位置 $(x,y)$ 均为整数
## 输出格式
请输出允许所有奶牛通信的网络的最低成本。请注意,此开销可能太大,无法放入 32 位整数中,并且可能需要使用 64 位整数(例如,C++中的“long long”)。
### 说明/提示
测试点 2~3 满足 $N\le1000$。
测试点 4~15 没有特殊限制。
题目描述
Farmer John's $N$ cows $(1≤N≤10^5)$ are spread far apart on his farm and would like to build a communication network so they can more easily exchange electronic text messages (all of which of course contain variations of "moo").
The ith cow is located at a distinct location $(x_i,y_i)$ where $0≤x_i≤10^6$ and $0≤y_i≤10$. The cost of building a communication link between cows $i$ and $j$ is the squared distance between them: $(x_i-x_j)^2+(y_i-y_j)^2$.
Please calculate the minimum cost required to build a communication network across which all the cows can communicate. Two cows can communicate if they are directly connected by a link, or if there is a sequence of links along which their message can travel.
**Note: the time limit for this problem is 4s, twice the default.**
输入输出格式
输入格式
The first line of input contains $N$, and the next $N$ lines each describe the $x$ and $y$ coordinates of a cow, all integers.
输出格式
Please output the minimum cost of a network that will allow all cows to communicate. Note that this cost might be too large to fit into a 32-bit integer and may require use of 64-bit integers (e.g., "long long" integers in C++).
输入输出样例
输入样例 #1
10
83 10
77 2
93 4
86 6
49 1
62 7
90 3
63 4
40 10
72 0
输出样例 #1
660
说明
【数据范围】
- Test cases 2-3 satisfy $N≤1000$.
- Test cases 4-15 satisfy no additional constraints.