求助啊各位
7分 剩下点全WA
为了方便大家看我加上了墨迹注释
#include<bits/stdc++.h>
using namespace std;
int m,mp[505][505],ans;
bool flag=false,vis[505][505];
void search(int x,int y,int step)
{
if(x<1||y<1||x>505||y>505)
return;
if(flag==true)
return;
if(vis[x][y]==true)
return;
if(mp[x][y]!=-1&&mp[x][y]<=step)
return;
if(mp[x][y]==-1)
{
ans=step;
flag=true;
return;
}
vis[x][y]=true;
search(x+1,y,step+1);
search(x,y+1,step+1);
search(x-1,y,step+1);
search(x,y-1,step+1);
vis[x][y]=false;
}
int main(){
cin>>m;
memset(mp,-1,sizeof(mp));
for(int i=1;i<=m;i++)
{
int x,y,t;
cin>>x>>y>>t;
mp[x][y]=t;
mp[x+1][y]=t;
mp[x-1][y]=t;
mp[x][y+1]=t;
mp[x][y-1]=t;
}
search(0,0,0);
if(flag==false)
{
cout<<-1<<endl;
}
else
{
cout<<ans<<endl;
}
return 0;
}