摘要: 最近公共祖先LCA int LCA(int x,int y) { if(dep[x]<dep[y]) swap(x,y); int d=dep[x]-dep[y]; for(int p=0,k=1;p<k;p++,k<<=1) if(d&k) x=f[p][x]; if(x==y) return x 阅读全文
posted @ 2020-07-23 20:13 Allen_lml 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 树链剖分 void dfs1(int x) { sz[x]=1; for(int i=b[x];i;i=nxt[i]) { if(to[i]==f[x]) continue; f[to[i]]=x; dep[to[i]]=x; dep[to[i]]=dep[x]+1; dfs1(to[i]); sz 阅读全文
posted @ 2020-07-23 20:09 Allen_lml 阅读(112) 评论(0) 推荐(0) 编辑