#P2212. Irrigation System
Irrigation System
Irrigation System
Farmer John has N fields (1 ≤ N ≤ 2000) located in the 2D plane. Field i is represented by a distinct point ( (x_i, y_i) ) with ( 0 \le x_i, y_i \le 1000 ). The cost to build a water pipe between field i and field j is equal to the squared Euclidean distance: [ (x_i - x_j)^2 + (y_i - y_j)^2 ] However, the contractor will only install a pipe if its cost is at least ( c ) (1 ≤ c ≤ 1,000,000). Help Farmer John compute the minimum total cost required to connect all his fields (i.e. to build a network such that water from any field can reach any other field using the pipes). If it is impossible to connect all the fields under the given condition, output -1.
inputFormat
The first line contains two integers ( n ) and ( c ): the number of fields and the minimum allowed cost for each pipe. Each of the next ( n ) lines contains two integers ( x_i ) and ( y_i ), representing the coordinates of the i-th field.
outputFormat
Output a single integer representing the minimum total cost to connect all the fields according to the rules. If it is impossible, output -1.
sample
4 1
0 0
0 1
1 0
1 1
3
</p>