Bzoj 1455 Roma games can be stacked naked

Source: Internet
Author: User

Test Instructions:Link Method:Can and Heap parsing:The first day of the second to forget, said can and heap, so to find the naked topic to brush. For a merge operation, if one is empty then the root is another. Then we may as well assume that the X key value is less than Y. So the left-leaning tree is the left-leaning tree, so the whole process forms a recursive one that merges the right subtree of x with the subtree of y as the root. After merging, the left side is maintained, that is, the left side of NPL is greater than right. The root node's NPL is then updated. In fact, this is the whole process of merging, only to deepen the memory of the narrative. Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 1000010using namespace STD;intch[n][2],h[n],key[n],fa[n];BOOLCol[n];intFindintx) {returnX==fa[x]?x:fa[x]=find (Fa[x]);}intMergeintXintY) {if(!x)returnYif(!y)returnXif(Key[y]<key[x]) swap (x, y); ch[x][1]=merge (ch[x][1],y);if(h[ch[x][1]]>h[ch[x][0]]) Swap (ch[x][0],ch[x][1]);if(!h[ch[x][1]]) h[x]=0;Elseh[x]=h[ch[x][1]]+1;returnx;}intN,q;Chars[5];intMain () {scanf("%d", &n); for(intI=1; i<=n;i++)scanf("%d", &key[i]); for(intI=1; i<=n;i++) fa[i]=i; h[0]=-1;scanf("%d", &q); for(intI=1; i<=q;i++) {scanf('%s ', s);if(s[0]==' M ')        {intx, y;scanf("%d%d", &x,&y);if(col[x]| | Col[y])Continue;intFx=find (x), Fy=find (y);if(FX!=FY) {intT=merge (FX,FY);            fa[fx]=t,fa[fy]=t; }        }Else{intXscanf("%d", &x);if(Col[x])printf("%d\n",0);Else{intFx=find (x); col[fx]=1;printf("%d\n", Key[fx]); Fa[fx]=merge (ch[fx][0],ch[fx][1]);            FA[FA[FX]]=FA[FX]; }        }    }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Bzoj 1455 Roma games can be stacked naked

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.