NOI Contest Archive

Archive / 2020 / Final Round — Day 2

Find the Worlds

Medium · National Olympiad in Informatics Sri Lanka 2020 - Day 2

There are M known worlds in a two-dimensional universe. Each world contains one or more cities, and each city will be located in one of those M worlds. A city is a point in the 2D universe that is represented by an integer coordinate (x,y). No more than 1 city will share the same coordinate.

The distance between two cities is the euclidean distance (the distance of the straight line) between the two points. All the cities in the universe are laid out satisfying the following conditions:

Given the location of cities, find the number of worlds in the universe and the number of cities in each world.

Input Format

The first line contains the number of cities, N
Each of the next N lines contains 2 integers separated by a space representing X,Y coordinate of a city.

Output Format

The first line should contain the number of worlds in the universe, M
The second line should contain the number of cities in each of those M worlds. These M integers should be separated by a space and sorted in the ascending order.

Constraints

At least 30% of test cases will have N \(\leq\) 10,000

Limits

Sample Input 0

5
2 1
3 1
2 100000
2 100002
1 1

Sample Output 0

2
2 3