请各位巨佬看看我哪里写的不对
#include<bits/stdc++.h>
using namespace std;
int m,n,ans=INT_MAX;
int tx[4]={0,0,-1,1},ty[4]={-1,1,0,0};
int maps[110][110],history[110][110],yon[110][110];
void dfs(int x,int y,int cost,int magic){
if(history[x][y]<cost) return;
history[x][y]=cost;
if(cost>ans) return;
if(x==m&&y==m){
ans=min(ans,cost);
return;
}
for(int i=0;i<4;i++){
int x1,x2;
x1=x+tx[i];
x2=y+ty[i]; cout<<x1<<" "<<x2<<endl;
if(x1<=0||x1>m||x2<=0||x2>m) return;
if(yon[x1][x2]==0){
yon[x1][x2]==1;
if(maps[x1][x2]!=0) {
if(maps[x][y]==maps[x1][x2]) dfs(x1,x2,cost,0);
else dfs(x1,x2,cost+1,0);
}
else {
if(magic==0){
maps[x1][x2]==maps[x][y];
dfs(x1,x2,cost+2,1);
maps[x1][x2]=0;
}
}
yon[x1][x2]==0;
}
}
}
int main(){
cin>>m>>n;
memset(history,ans,sizeof(history));
for(int i=1;i<=n;i++){
int x,y,c;
cin>>x>>y>>c;
maps[x][y]=c+1;
}
for(int i=1;i<=m;i++)
for(int j=1;j<=m;j++)history[i][j]=INT_MAX;
dfs(1,1,0,0);
if(ans==INT_MAX) cout<<-1;
else cout<<ans<<endl;
return 0;
}