The mayor of the Sky-Dragon city, Mr. Good, would like to build a monorail trolley system to promote the tourism industry.
There are N scenic sites in the city, and Mr. Good would like all of them to be connected by the monorails.
Furthermore, there are Q optional sites which Mr. Good may want to include some of them.
These Q sites are ordered decreasingly by the interestingness,
so Mr. Good may choose to include first-q of them, where 0<= q <= Q.
You are asked to calculate the minimum cost of each possible choice.
The cost to build the monorails is 1 million dollars per kilometer.
The rails have to be built along the existing roads in the city.
The Sky-Dragon city is well designed so that all the roads run north-south or east-west.
The north-south roads are called avenues, numbered from 1 (west-most) to X (east-most).
Similarly, the east-west roads are called streets, numbered from 1 (south-most) to Y (north-most).
Two neighboring avenues are 1 kilometer apart, so as two neighboring streets.
All the scenic sites are located at the intersection of a street and an avenue.
We would use (x,y) to denote the intersection of the x-th avenue and the y-th street.
There will be one station at each scenic site, and no other station will be built.
Due to the high cost and technical difficulties, there should not be any switches on the rails.
That is, each monorail line should connect two stations directly,
and two monorail lines cannot share any piece of rails, even if they lie on the same road.
However, it is allowed to have two or more rails on the same road, since they can be differentiated vertically.
Now, given N, Q, and the locations of the sites, please calculate the minimum cost of Q+1 possible choices.
The first line of the input contains an integer T, indicating the number of test cases.
There is always a blank line between two consecutive test cases.
Each test case starts with a line of two integers N and Q.
Then N+Q lines follow.
The i-th line contains xi and yi, which denote the location of the i-th scenic site.
The first N sites are required, and the last Q sites are optional (as described above).
It is guaranteed that the location of each site is different from all the other sites.
0<= N<=200000, 0<= Q<= 500, 1<= xi, yi<= 106.
For each test case please output Q+1 lines.
The i-th line should contain the minimum cost where q=i-1.
The output of two consecutive test cases should be separated by a blank line.
1 3 1 1 1 2 3 3 2 2 2
5 4
Migrated from old NTUJ.
scan, Ferng
No. | Testdata Range | Score |
---|