#4745. [Usaco2016 Dec]Cow Checklist

内存限制:128 MiB 时间限制:10 Sec

题目描述

Every day, Farmer John walks through his pasture to check on the well-being of each of his cows. Onh
is farm he has two breeds of cows, Holsteins and Guernseys. His HH Holsteins are conveniently number
ed 1…H, and his GG Guernseys are conveniently numbered 1…G (1≤H≤1000,1≤G≤1000). Each cowis loc
ated at a point in the 2D plane (not necessarily distinct).Farmer John starts his tour at Holstein 1
, and ends at Holstein HH. He wants to visit each cow along the way, and for convenience in maintain
ing his checklist of cows visited so far, he wants to visit the Holsteins and Guernseys in theorder 
in which they are numbered. In the sequence of all H+GH+G cows he visits, the Holsteins numbered 1…
H should appear as a (not necessarily contiguous) subsequence, and likewise for the Guernseys. Other
wise stated, the sequence of all H+GH+G cows should be formed by interleaving the list of Holsteins 
numbered 1…H with the list of Guernseys numbered 1…GWhen FJ moves from one cow to another cow trav
eling a distance of D, he expends D2 energy. Please help him determine the minimum amount ofenergy r
equired to visit all his cows according to a tour as described above.
有A、B两类点在一个二维平面上,A类的点有n个,B类的点有m个,要求从A类点的第1个开始走,走到第n个结束,
所有点必须有序(编号从小到大)但可以不连续地经过一次。
求在满足条件的情况下,最短的所经过的路径的欧几里得距离平方和是多少。

输入格式

The first line of input contains H and G, separated by a space.
The next H lines contain the xx and yy coordinates of the HH Holsteins, and the next G lines after 
that contain coordinates of the Guernseys. Each coordinate is an integer in the range 0…1000

输出格式

Write a single line of output, giving the minimum energy required for FJ's tour of all the cows.

样例

样例输入


			
3 2
0 0
1 0
2 0
0 3
1 3

样例输出


			
20

数据范围与提示