#include <iostream>
#include <queue>
using namespace std;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int m;
struct pos{
int safe,t;
pos():safe(true){
}
};
struct Node{
int x,y,value;
};
pos danger[301][301];
bool vis[301][301];
void BFS();
int main(){
cin>>m;
int x,y,t;
for(int i=0;i<m;i++){
cin>>x>>y>>t;
danger[x][y].safe=
danger[x+1][y].safe=false;
if(x!=0)
danger[x-1][y].safe=false;
danger[x][y+1].safe=false;
if(y!=0)
danger[x][y-1].safe=false;
danger[x][y].t=
danger[x+1][y].t=t;
if(x!=0)
danger[x-1][y].t=t;
danger[x][y+1].t=t;
if(y!=0)
danger[x][y-1].t=t;
}
BFS();
return 0;
}
void BFS(){
queue<Node> q;
Node head,tmp;
head.value=head.x=head.y=0;
q.push(head);
while(!q.empty()){
head=q.front();
q.pop();
if(danger[head.x][head.y].safe){
cout<<head.value;
return ;
}
for(int i=0;i<4;i++){
tmp.value=head.value+1;
tmp.x=head.x+dx[i];
tmp.y=head.x+dy[i];
if(danger[tmp.x][tmp.y].safe){
q.push(tmp);
continue;
}
if(danger[tmp.x][tmp.y].t>tmp.value)
q.push(tmp);
}
}
}
样例无输出?