树链剖分
来源:互联网 发布:mac dock图标大小 编辑:程序博客网 时间:2024/06/06 03:14
#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int N=1e5;const int M=N;struct Edge { int v,next; Edge(int v=-1,int next=-1):v(v),next(next){}}e[M*2];int head[N],total;void init(){ memset(head,-1,sizeof(head));total=0;}void adde(int u,int v){ e[total]=Edge(v,head[u]);head[u]=total++;}int dep[N],sz[N],fa[N],son[N];void getson(int u,int f){///重儿子 dep[u]=dep[f]+1;sz[u]=1;fa[u]=f;son[u]=-1; for(int i=head[u];i!=-1;i=e[i].next){ int v=e[i].v; if(v==f)continue; getson(v,u); sz[u]+=sz[v]; if(son[u]==-1||sz[son[u]]<sz[v])son[u]=v; }}int top[N],p[N],fp[N],pos;void getpos(int u,int clo){////重链在p中连续 top[u]=clo; p[u]=++pos; fp[pos]=u; if(son[u]==-1)return ; getpos(son[u],clo); for(int i=head[u];i!=-1;i=e[i].next){ int v=e[i].v; if(v!=son[u]&&v!=fa[u]){ getpos(v,v); } }}////////seg_tree;void lca(int u,int v){ int fu=top[u],fv=top[v]; while(fu!=fv){ if(dep[fu]<dep[fv]){ swap(fu,fv); swap(u,v); } ///L=p[fu],R=p[u];update(1,pos,1); u=fa[fu];fu=top[u]; } if(dep[u]>dep[v])swap(u,v); ////L=p[u],R=p[v];update(1,pos,1);}void solve(){ pos=0; dep[0]=0; getson(1,0); getpos(1,1);}int main(){ return 0;}
0 0
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- 树链剖分
- uva 331 Mapping the Swaps
- 树状数组
- K-means算法对地图上点进行聚类(未修订篇)
- 多层循环的跳出(return goto break continue 的用法与区别)
- spring4之搭建restful风格的web服务
- 树链剖分
- 用IBExpert管理firebird
- 机器学习(四):BP神经网络_手写数字识别_Python
- 莫队
- RTMPDump开源工程
- 后缀自动机
- 编程之美--游戏之乐--1.7光影切割问题
- shell中if做比较
- 百度搜索有哪些URL参数呢?