mendessy @ 2019-09-06 17:12:30
rt,但是为什么我这道题打树剖lca超时了但是倍增lca反而过了? 以下是树剖lca代码(倍增lca就不贴了)
void dfs2(int now,int fatop)
{
top[now]=fatop;
if(son[now])
dfs2(son[now],fatop);
for(register int i=first[now];i;i=next[i])
{
int x=to[i];
if(x==fa[now] || x==son[now])
continue;
dfs2(x,x);
}
}
inline int LCA(int x,int y)
{
while(top[x]!=top[y])
{
if(deep[top[x]]<deep[top[y]])
swap(x,y);
x=fa[top[x]];
}
return deep[x]<deep[y]?x:y;
}
by SSerxhs @ 2019-09-06 17:29:30
非要卡的话可以让树剖卡满,而且这种情况下倍增是loglogn
by 1saunoya @ 2019-09-06 17:36:00
@SSerxhs 怎么卡啊
by _FILARET_ @ 2019-09-06 17:41:41
不会树剖只会倍增的蒟蒻瑟瑟发抖
by NaCly_Fish @ 2019-09-06 17:44:24
@mendessy 我树剖过了
by mendessy @ 2019-09-06 18:06:46
@NaCly_Fish 我看了看你和我的树剖lca,我感jio差不多
by SSerxhs @ 2019-09-06 20:57:05
@清风ღ 详见ddp加强版