A heap and a check set correspond, and meet and check the concentration of all who are not dead equals the people in the heap
1 /**************************************************************2 problem:14553 user:idy0024 language:c++5 result:accepted6 time:2688 Ms7 memory:32336 KB8 ****************************************************************/9 Ten#include <cstdio> One #defineN 1000010 A - structNode { - intu, W, S; theNode *ls, *rs; - voidUpdate () { -s =1; - if(ls) s + = Ls->s; + if(RS) s + = Rs->s; - } +}pool[n], *tail=pool, *Root[n]; A at intN, M; - intFat[n], die[n]; - - intFindinta) { - returnA==fat[a]? a:fat[a]=find (Fat[a]); - } inNode *newnode (intUintW) { -Node *nd = + +tail; toNd->u =u; +Nd->w =W; -Nd->ls = Nd->rs =0; the returnnd; * } $Node *smerge (node *na, node *nb) {Panax Notoginseng if(!na &&!NB)return 0; - if(!na)returnnb; the if(!NB)returnna; + if(Na->w < nb->W) { ANa->rs = Smerge (na->RS, NB); theNa->update (); + returnna; -}Else { $Nb->rs = Smerge (nb->rs, NA); $Nb->update (); - returnnb; - } the } - intMain () {Wuyiscanf"%d", &n); the for(intI=1, W; i<=n; i++ ) { -scanf"%d", &W); WuRoot[i] =NewNode (i,w); -Fat[i] =i; About } $scanf"%d", &m); - for(intI=1, U,v; i<=m; i++ ) { - Charch[Ten]; -scanf"%s", ch); A if(ch[0]=='M' ) { +scanf"%d%d", &u, &v); the if(Die[u] | | die[v])Continue; - intFu =find (u); $ intFV =Find (v); the if(FU==FV)Continue; theFAT[FU] =FV; theROOT[FV] =Smerge (Root[fu], ROOT[FV]); the}Else { -scanf"%d", &u); in if(Die[u]) { theprintf"0\n" ); the Continue; About } the intFu =find (u); the intv = root[fu]->u; theprintf"%d\n", root[fu]->W); +DIE[V] =true; -ROOT[FU] = Smerge (Root[fu]->ls, root[fu]->rs); the }Bayi } the}
View Code
Bzoj 1455 can be stacked + and check set