在本地写树上问题时发现大样例RE了,是爆栈,但是不知道是什么问题,递归代码如下:
void dfs1(int x,int fa){
f[x][0]=fa;cnt[x]=0ll;
depth[x]=depth[fa]+1ll;
for(int i=1;i<=20;i++){
f[x][i]=f[f[x][i-1]][i-1];
}
for(int i=head[x];i;i=e[i].nxt){
int v=e[i].to;
if(v==f[x][0])continue;
a1[v]=e[i].val1;a2[v]=e[i].val2;
dfs1(v,x);
}
}
经本地测试,在主函数中调用如下 test() ,递归只能运行40000层左右就会爆栈
int u=0;
void test(){
u++;
printf("u=%lld\n",u);
test();
}
是本人的Dev有什么问题吗?