**求指教**
```cpp
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a[1001][1001],b[1001][1001],flag=0;
bool bb[1001][1001];
int xx[4]={1,0,-1,0};
int yy[4]={0,1,0,-1};
int n,m,ans=99999;
void dfs(int x,int y,int hh)
{
if(b[x][y]!=9)
flag=0;
if(hh>=ans)
{
//cout<<1;
return ;
}
if(x==n&&y==n)
{
//cout<<<<endl;
ans=min(ans,hh);
//cout<<1;
return ;
}
for(int i=0;i<4;i++)
{
int e=x+xx[i],r=y+yy[i];
if(e<=n&&e>=1&&r<=n&&r>=1&&bb[e][r]==false)
{
if(b[e][r]!=9)
{
if(b[e][r]==b[x][y])
{
bb[e][r]=true;
dfs(e,r,hh);
bb[e][r]=false;
}
else
{
bb[e][r]=true;
dfs(e,r,hh+1);
bb[e][r]=false;
}
}
if(b[e][r]==9&&flag==0)
{
flag=1;
bb[e][r]=true;
dfs(e,r,hh+2);
flag=0;
bb[e][r]=false;
b[e][r]=9;
}
}
}
}
int main()
{
memset(b,9,sizeof(b));
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int o,p,z;
cin>>o>>p>>z;
b[o][p]=z;
}
bb[1][1]=true;
dfs(1,1,0);
if(ans!=99999)
cout<<ans;
else
cout<<-1;
return 0;
}
```
by 初嫁QAQ @ 2019-01-02 21:16:21
@[Eternal_Sz](/space/show?uid=102003)
**把A【x】【y】=c++改为++c**
by 初嫁QAQ @ 2019-01-04 16:45:03