#P2906. [USACO08OPEN] Cow Neighborhoods G
[USACO08OPEN] Cow Neighborhoods G
Description
People who know cows understand how they form "cow neighborhoods." They observed Farmer John’s cows (numbered through ) grazing on a pasture modeled as a plane with and coordinates starting from , where each cow is located at a unique integer lattice point.
Two cows are neighbors if at least one of the following criteria holds:
- Their Manhattan distance is at most , i.e., .
- They share a common neighbor; that is, there exists a cow such that and , and and , both belong to the same group.
Given the cows’ positions and the distance , determine the number of "cow neighborhoods" and the number of cows in the largest "cow neighborhood."
For example, consider the pasture below. When , this pasture has four neighborhoods: one large neighborhood on the left, two neighborhoods of size , and a huge neighborhood on the right containing distinct cows.
.....................................*.................
....*...*..*.......................***.................
......*...........................****.................
..*....*..*.......................*...*.******.*.*.....
........................*.............***...***...*....
*..*..*...*..........................*..*...*..*...*...
.....................................*..*...*..*.......
.....................................*..*...*..*.......
...*................*..................................
.*..*............................*.*.*.*.*.*.*.*.*.*.*.
.*.....*..........................*.*.*.*.*.*.*.*.*.*.*
....*..................................................
Input Format
The first line contains two space-separated integers .
Each of the next lines contains two space-separated integers , giving the coordinates of a cow.
Output Format
Output a single line with two space-separated integers: the number of "cow neighborhoods" and the size of the largest "cow neighborhood."
4 2
1 1
3 3
2 2
10 10
2 3
Hint
Sample Explanation #1
There are neighborhoods in the sample: one formed by the first three cows, and the other by the last cow. Therefore, the largest neighborhood size is .
Constraints
For of the testdata, , , , and are integers.
Translated by ChatGPT 5
京公网安备 11011102002149号