#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<sstream>
#include <map>
using namespace std;
#define L 101
#define MAX 0x3f
int m,n;
//int g[L][L]; //占位
int x,y,k1,k2;
int s,t=0;
int mov[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int wmax,wmin,hmax,hmin;
/*int g(int i,int j){ //模拟负key数组
}*/
int father[L];
int num[L]; //实时统计
int maxl;
bool flag=false;
map<int, map<int, int> > g; //可以模拟负key数组 => 默认值为0
map<int, map<int, int> > gg; //本轮感染不再染
int find(int k){
if(father[k]!=k)father[k] = find(father[k]);
return father[k];
}
void unity(int x,int y){
k1=find(x);
k2=find(y);
if(k1!=k2){
father[k1]=k2; //合并代表
num[k1]+=num[k2];
maxl = max(maxl,num[k1]);
if(maxl>=n) flag = true;
}
}
int main()
{
cin >> n;
for(int i=1;i<=n;i++){
cin >> x >> y;
g[x][y]=i; //初始占位
wmax=max(wmax,x); //记录最大边界
hmax=max(hmax,y);
wmin=min(wmin,x);
hmin=min(hmin,y);
father[i]=i;
num[i]=1;
}
while(1){
t++; //累加时间
for(int i=wmin;i<=wmax;i++){
for(int j=hmin;j<=hmax;j++){
if(g[i][j] && !gg[i][j]){ //已经占领了 => 扩张
for(int k=0;k<=3;k++){
x = i+mov[k][0];
y = j+mov[k][1];
if(!g[x][y]){g[x][y] = g[i][j];gg[x][y]=1;} //扩张
else{unity(g[i][j],g[x][y]);}
}
}
if(flag){cout << t;return 0;}
}
}
gg.erase(gg.begin(),gg.end());
wmax+=1; //必定扩展边界
hmax+=1;
wmin-=1;
hmin-=1;
}
return 0;
}
/*
2
0 0
5 5
*/
//cout << "输入:"
结果: