People in buildings

3.6

28 votes
Backtracking Basic, Hard, Algorithms, Backtracking
Problem

There N people in your city. An id is associated with each of the citizens and numbered from 1 to N. You know the exact coordinates (x, y) of the location where each citizen lives. Your task is to move all these people to some buildings. You can build a building at any time at any place instantly. The building will be sustainable only if at least G people are moved to the building.  

You are required to move each of the citizens by using the minimum possible time. People can move one unit distance per unit time and the distance of two locations in the 2D-plane is equal to their Euclidean distance. 

Your task is to determine a solution so that the required time to move all the citizens to the building is minimized.

Input format

  • First line: A single integer N denoting the number of citizens
  • Next line contains a single integer G denoting the minimum number of people required in a building
  • Next N lines: Contains two integers xi and yi where the ith of these lines denote the coordinates of the citizen with id=i

Output format

The format of the output is as follows:

  • First line: Print S that denotes the number of buildings that you can build in your solution.
  • 2S lines:
    • (2i1)th of these lines: A single integer that denotes the number of citizens moved to the ith building
    • (2i)th of these lines: id 's of the citizens that are moved to the ith building, in any order.

Note:

  • You are not required to print the minimum time that is required to move all the citizens to buildings.
  • You are not required to print the coordinates of the buildings' locations.
  • You are not required to minimize S that denotes the number of buildings that are used in your solution.
  • Your score will be calculated automatically based on the explained solution.
  • The test data is randomly generated.

Constraints

2N103

1xi,yi109

2GN

Time Limit: 5
Memory Limit: 512
Source Limit:
Explanation

There is no way to build 2 safe houses with at least 3 citizens in each of them.

So we must move all the citizens to one safe house.

Best position to build the safe house is (1.5,1.5)

Editor Image

?