"BZOJ2049" "SDOI2008" Cave Cave survey LCT nude template problem array version

Source: Internet
Author: User

Array, at least for now I only write arrays, not write pointers.


LCT This stuff I'm not going to talk about or anything messy anyway this one is for personal use.

Similarly, the person who looks at this blog can first go to other places to learn LCT, and then come to my code.


Code:

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define LS son[x][ 0] #define RS son[x][1] #define IS (x) (x==son[fa[x]][1]) #define ISROOT (x) (x!=son[fa[x]][0]&&x!=son[fa[x]][1]) #define N 10010#define inf 0x3f3f3f3fusing namespace std;int pos[n],n,m;char ttt[10];struct lct{int son[n][2],fa[n],cnt; BOOL Flag[n];int stack[n],top;void Joint (int x,int y,int d) {fa[x]=y,son[y][d]=x;} void reverse (int x) {flag[x]^=1;swap (ls,rs);} void pushdown (int x) {if (flag[x]) {reverse (x); flag[ls]^=1,flag[rs]^=1;flag[0]=0;}} int NewNode () {Cnt++;son[cnt][0]=son[cnt][1]=fa[cnt]=0;return cnt;} void Pushpath (int x) {for (top=0;! IsRoot (x); x=fa[x]) stack[++top]=x;stack[++top]=x;for (int i=top;i;i--) pushdown (Stack[i]);} void rotate (int x) {int y=fa[x],z=fa[y],i=is (x), T=son[x][!i];if (!isroot (y)) joint (X,z,is (y)); else Fa[x]=z;joint (T,y, i), joint (y,x,!i); fa[0]=son[0][0]=son[0][1]=0;} void splay (int x) {pushpath (x); int Y,z;while (!isroot (x)) {y=fa[x],z=fa[y];if (IsRoot (y)) {rotate (x); bReak;} Rotate (is (x) ==is (y)? y:x), rotate (x);}} void access (int x) {int p=0;while (x) {splay (x); rs=p,p=x,x=fa[x];}} void makeroot (int x) {access (x); splay (x); Flag[x]=1;pushdown (x);} void link (int x,int y) {makeroot (x); fa[x]=y;} void cut (int x,int y) {makeroot (y); access (x); splay (x); ls=fa[y]=0;} int findroot (int x) {while (fa[x]) X=fa[x];return x;}} Lct;int Main () {//freopen ("test.in", "R", stdin); int i,a,b;scanf ("%d%d", &n,&m); for (i=1;i<=n;i++) pos[i]= Lct.newnode (); for (i=1;i<=m;i++) {scanf ("%s", TTT), scanf ("%d%d", &a,&b), if (ttt[0]== ' C ') Lct.link (Pos[a], POS[B]), else if (ttt[0]== ' D ') lct.cut (Pos[a],pos[b]), else {if (Lct.findroot (Pos[a]) ==lct.findroot (Pos[b]) puts ("Yes "); else puts (" No ");}} return 0;}


"BZOJ2049" "SDOI2008" Cave Cave survey LCT nude template problem array version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.