Looks like Konjac Konjac I'm just retiring.
This problem is to maintain the sub-tree and, delete the current largest element in the subtree, and can merge two subtree information, think of the left-leaning tree ...
Done 233.
1 /**************************************************************2 problem:28093 User:rausen4 language:c++5 result:accepted6 time:804 Ms7 memory:7624 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <algorithm> A - using namespacestd; -typedefLong Longll; the Const intN =100005; - - structheap{ - intV, L, R, DEP; + }h[n]; - intcnt_heap; + A structEdge { at intnext, to; - Edge () {} -Edgeint_n,int_t): Next (_n), to (_t) {} - } E[n]; - intfirst[n], tot; - in structTree_node { - intCost , L, Root; to ll sum, sz; + } Tr[n]; - the intN, M; * ll ans; $ Panax NotoginsengInlineintRead () { - intx =0, SGN =1; the CharCH =GetChar (); + while(Ch <'0'||'9'<ch) { A if(ch = ='-') SGN =-1; theCH =GetChar (); + } - while('0'<= CH && Ch <='9') { $x = x *Ten+ CH-'0'; $CH =GetChar (); - } - returnSGN *x; the } - WuyiInlinevoidAdd_edge (intXinty) { theE[++tot] =Edge (first[x], y); -FIRST[X] =tot; Wu } - AboutInlineintNew_heap (intx) { $H[++CNT_HEAP].V =x; -H[CNT_HEAP].L = H[CNT_HEAP].R = H[CNT_HEAP].DEP =0; - returncnt_heap; - } A + intMerge (intXinty) { the if(!x | |!y)returnX +y; - if(H[X].V <h[y].v) $ swap (x, y); theH[X].R =Merge (H[X].R, y); the if(H[h[x].l].dep <H[H[X].R].DEP) the swap (H[X].L, H[X].R); theH[X].DEP = H[H[X].R].DEP +1; - returnx; in } the theInlineintTop (intp) { About returnh[p].v; the } the the voidPop (int&p) { +p =Merge (H[P].L, H[P].R); - } the Bayi voidDfsintp) { the intx, y; theTr[p].root =new_heap (tr[p].cost); -Tr[p].sum = tr[p].cost, Tr[p].sz =1; - for(x = first[p]; x; x =E[x].next) { theDfs (y =e[x].to); theTr[p].sum + = tr[y].sum, Tr[p].sz + =Tr[y].sz; theTr[p].root =Merge (Tr[p].root, tr[y].root); the } - while(Tr[p].sum >m) { theTr[p].sum-=Top (Tr[p].root), Pop (tr[p].root); the--Tr[p].sz; the }94ans = max (ans, tr[p].sz *tr[p].l); the } the the intMain () {98 inti, X; Aboutn = Read (), M =read (); - for(i =1; I <= N; ++i) {101x =read ();102 Add_edge (x, i);103Tr[i].cost = Read (), TR[I].L =read ();104 } theDfs1);106printf"%lld\n", ans);107 return 0;108}
View Code
The Department of Education is going to die for me!!!
BZOJ2809 [apio2012]dispatching