求助,为什么全RE
#include <iostream>
using namespace std;
int n,k,ans;
int f[]={1,-1};
bool used[100005];
void bfs(int start,int end)
{
int head=1,tail=0,q[100005],p[100005];
tail++;
q[tail]=start;
p[tail]=0;
used[start]=1;
while(head<=tail)
{
int c=q[head];
int pp=p[head];
head++;
for(int i=0;i<2;i++)
{
if(used[c+f[i]]==0)
{
if(c+f[i]>=0 and c+f[i]<=100005)
{
tail++;
q[tail]=c+f[i];
p[tail]=pp+1;
used[c+f[i]]=1;
if(c+f[i]==end)
{
cout<<p[tail];
return ;
}
}
}
}
if(used[c*2]==0)
{
if(c*2>=0 and c*2<=100005)
{
tail++;
q[tail]=c*2;
p[tail]=pp+1;
if(c*2==end)
{
cout<<p[tail];
return ;
}
}
}
}
}
int main()
{
// freopen(".in","r",stdin);
// freopen("","w",stdout);
cin>>n>>k;
bfs(n,k);
return 0;
}