bzoj3011[usaco2012 dec]running away from the barn*

Source: Internet
Author: User

bzoj3011[usaco2012 dec]running away from the Barn

Test instructions

Give a tree with a edge at the root of point 1th, and ask the number of points in the subtree of each point that is less than L. The size of the tree is ≤200000.

Exercises

Each node maintains a tag-and-Heap, DFS when the child node of the heap plus the current node to the child node of the Benquan, after which it is merged with the heap of the current node.

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <queue>5 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 #defineMAXN 2000107 #definell Long Long8 using namespacestd;9 Ten inline ll read () { One     CharCh=getchar (); ll f=1, x=0; A      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} -      while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); -     returnf*x; the } - intrt[maxn],n,ch[maxn][2],ANS[MAXN]; ll V[maxn],tg[maxn],l; - structe{intT ll W;intn;} ES[MAXN];intg[maxn],ess; - voidPushdown (intx) { +     if(Tg[x]) { -         if(ch[x][0]) v[ch[x][0]]+=tg[x],tg[ch[x][0]]+=Tg[x]; +         if(ch[x][1]) v[ch[x][1]]+=tg[x],tg[ch[x][1]]+=Tg[x]; Atg[x]=0; at     } - } - intMergeintXinty) { -     if(!x| |! YreturnX+y;if(v[x]<V[y]) swap (x, y); Pushdown (x); -ch[x][1]=merge (ch[x][1],y); Swap (ch[x][0],ch[x][1]);returnx; - } in intPopintx) { -Pushdown (x);returnMerge (ch[x][0],ch[x][1]); to } + voidDfsintXintFA) { -      for(intI=G[X];I;I=ES[I].N)if(es[i].t!=FA) { theDFS (ES[I].T,X); TG[RT[ES[I].T]]+=ES[I].W; v[rt[es[i].t]]+=ES[I].W; *Rt[x]=merge (rt[x],rt[es[i].t]); ans[x]+=ans[es[i].t]; $     }Panax Notoginseng      while(v[rt[x]]>l) Rt[x]=pop (Rt[x]), ans[x]--; - } the intMain () { +N=read (); L=read (); Inc (I,2, N) {intX=read (); ll Y=read (); es[i-1]= (e) {i,y,g[x]}; g[x]=i-1;}  AInc (I,1, N) rt[i]=i,v[i]=0, tg[i]=0, ans[i]=1, ch[i][0]=ch[i][1]=0; Dfs1,0); theInc (I,1, N) printf ("%d\n", Ans[i]);return 0; +}

20161025

bzoj3011[usaco2012 dec]running away from the barn*

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.