http://icpc.upc.edu.cn/problem.php?id=7553
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
int d[4][2]= {{0,1},{0,-1},{1,0},{-1,0}};
struct str
{
int x,y,s;
};
queue<str>q;
int n,m,k,i,j,x,xx,yy,y,max1,v[2010][2010],a[20000][2];
void bfs()
{
while(q.size())
{
str k=q.front();
q.pop();
for(int i=0; i<4; i++)
{
int x=k.x+d[i][0],y=k.y+d[i][1];
if (x>=1&&x<=n&&y>=1&&y<=m&&v[x][y]==0)
{
v[x][y]=k.s+1;
q.push(str{x,y,k.s+1});
}
}
}
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(v,0,sizeof(v));
scanf("%d",&k);
for(i=0; i<k; i++){
scanf("%d%d",&xx,&yy);
v[xx][yy]=1;
q.push(str{xx,yy,1});
}
bfs();
max1=0;
for(i=1; i<=n; i++)
for(j=1; j<=m; j++)
if(v[i][j]>max1)
{
max1=v[i][j];
x=i;
y=j;
}
printf("%d %d\n",x,y);
}
}