update:2017.09.26

 #include <bits/stdc++.h>

 using namespace std;

 struct Link_Cut_Tree
{
static const int MAXN = + ; int ch[MAXN][], fa[MAXN], rev[MAXN], sz[MAXN];
int sk[MAXN]; bool isroot(int x)
{
return ch[fa[x]][] != x && ch[fa[x]][] != x;
} void reverse(int x)
{
rev[x] ^= , swap(ch[x][],ch[x][]);
} void update(int x)
{
sz[x] = sz[ch[x][]] + sz[ch[x][]] +;
} void push_down(int x)
{
if(!rev[x]) return ;
if(ch[x][]) reverse(ch[x][]);
if(ch[x][]) reverse(ch[x][]);
rev[x]=;
} void rotate(int x)
{
int f = fa[x], gf = fa[f];
int t1 = ( x != ch[f][]), t2 = ( f != ch[gf][]), tmp = ch[x][^t1];
if(!isroot(f)) ch[gf][^t2] = x;
fa[tmp] = f, fa[x] = gf, ch[x][^t1] = f, fa[f] = x, ch[f][^t1] = tmp;
update(f);
} void splay(int x)
{
int top = ;
sk[++top] = x;
for(int i = x; !isroot(i); i = fa[i]) sk[++top] = fa[i];
while(top) push_down(sk[top--]);
for(int f = fa[x], gf = fa[f]; !isroot(x); rotate(x), f = fa[x],gf = fa[f])
if(!isroot(f))
rotate((x==ch[f][]) ^ (f==ch[gf][]) ? x : f);
update(x);
} void access(int x)
{
for(int p = ; x; p = x, x = fa[x])
splay(x), ch[x][] = p, update(x);
} void makeroot(int x)
{
access(x), splay(x), reverse(x);
} int findroot(int x)
{
access(x), splay(x);
while(ch[x][]) x = ch[x][];
return x;
}
void link(int x,int y)
{
makeroot(x), fa[x] = y;
} void cut(int x,int y)
{
makeroot(x), access(y), splay(y);
if(ch[y][] == x) ch[y][] = fa[x] = ;
update(y);
} void debug(void)
{
for(int i=;i<=;i++)
printf("%d %d %d %d %d %d %d\n",i,fa[i],ch[i][],ch[i][],rev[i],sz[i]);
}
}lct; int main(void)
{ return ;
}

最新文章

  1. (C++) Include 文件
  2. myeclipse如何修改Web项目名称,eclipse如何修改项目名字
  3. ios页面保存至桌面logo大小
  4. http://highscalability.com/blog/2015/5/18/how-mysql-is-able-to-scale-to-200-million-qps-mysql-cluster.html
  5. C标准头文件&lt;assert.h&gt;
  6. Extjs的radio单选框的使用
  7. PHP date 格式化一个本地时间/日期
  8. Robotium 不能同时跑多个case
  9. QT+QT creator+OpenCV图像灰度化
  10. Prime Path(POJ 3126 BFS)
  11. MySQL千万级数据JDBC插入
  12. 转:Selenium中的几种等待方式,需特别注意implicitlyWait的用法
  13. EM阅读资料
  14. ES6 - 变量的解构赋值学习笔记
  15. python基础(str,list,tuple)
  16. 将DataRow拷贝到另一个DataRow
  17. thinkphp5 model 模型
  18. 开源网站流量统计系统Piwik源码分析——参数统计(一)
  19. cpp与其他语言相比较
  20. MAC apache服务器搭建

热门文章

  1. querySelectorAll 和getElementsByClassName的区别
  2. MyEclipse10.6 安装SVN插件方法及插件下载地址
  3. DML语句报错是因为控制文件无法扩大还是另有原因?
  4. hdu1244(dp)
  5. 1853: [Scoi2010]幸运数字[容斥原理]
  6. MySQL中关于SQL注入的相关需要的基础知识
  7. LeetCode-Water and Jug Problem
  8. js 闭包与垃圾回收-待删
  9. dbForge mysql数据库比对
  10. lofter个人网站文艺愤青下载