#P2848. Holstein's Tour
Holstein's Tour
Holstein's Tour
Farmer John has two breeds of cows on his farm: Holsteins and Guernseys. The Holsteins are numbered from to , and the Guernseys are numbered from to . Each cow is located at a point in the 2D plane. Farmer John begins his tour at Holstein and must finish at Holstein . He needs to visit every cow, but for convenience he wishes to visit the cows in the order of their numbering within each breed. In other words, in the overall tour of cows, the sequence of Holsteins and the sequence of Guernseys must each appear as a (not necessarily contiguous) subsequence.
When moving from one cow at point to the next cow at point , Farmer John expends energy equal to the square of the Euclidean distance, i.e.,
Your task is to determine the minimum total energy required for Farmer John to complete his tour under these conditions.
inputFormat
The first line of input contains two integers and (, ), representing the number of Holsteins and Guernseys respectively. The next lines each contain two integers, representing the and coordinates of the Holstein cows in order. The following lines each contain two integers, representing the and coordinates of the Guernsey cows in order.
outputFormat
Output a single integer which is the minimum total energy that Farmer John expends in his tour.
sample
2 1
0 0
1 0
0 1
3
</p>