Monopoly
Time limit1sMemory limit128 MB
Given points on a grid, connect two points with an edge when their Manhattan distance is at most c; report the number of connected components and the largest component size.
- Level
Medium7 of 10
- Topics
- Graph, Union-find, Sorting, Geometry
- Solved
- No attempts yet
Problem
The internet has finally reached Byteland. The first step in bringing the whole country online is to lay some cables in the capital. A company called Byteland Telecom (BT) is ready to take the job, but local regulations and infrastructure limits make it trickier than it first looks.
There are buildings in the capital, each sitting at the intersection of a street and an avenue. Streets run North to South and avenues run East to West. Any two adjacent parallel streets are byteyard apart, and likewise for avenues. Streets are numbered with consecutive integers from West to East, and avenues from South to North.
Internet cables may only run along streets and avenues. Connecting a building at coordinates (the intersection of street and avenue ) to a building at needs byteyards of cable. No single cable may be longer than byteyards, and cables may only be joined at buildings.
To prevent a monopoly, each telecom company may install at most one transmitter-receiver, placed on the roof of one building. That transmitter provides internet to everyone in any building connected to it, directly or indirectly, through the cable network.
BT's CEO wants to know two things: how many additional telecom companies are needed so that every building is served by at least one company, and the largest number of buildings BT can link into a single network.
Input
The first line contains two integers and (, ): the number of buildings and the maximum length of a single cable. Buildings are numbered from . Each of the next lines contains two integers and (): the coordinates of the -th building.
Output
Print two integers separated by a space: first, the minimum number of telecom companies other than BT that must provide service so that every building is covered; second, the maximum number of buildings BT can serve with a single transmitter while following all the rules.