Description
n points, forming a tree structure. With M release, select two dots x, y each time
For X-To-y paths (with x, y) each dots a bag of Z-type items. Complete
The maximum number of items that are stored at each point after the release.
Input
First line number N,m
Next N-1 line, two numbers a, b for each line, indicates an edge between A and B
Next m line, three numbers per line x, Y, Z. Title
Output
Output has n rows
The number per I-row indicates which of the items in the first
The number of items is the same, the output number is the smallest. If there is no item at a point
Then output 0
Off-line processing, tree-chain splits the tree into chains, and then records the difference (the current point is more than the previous point and what's missing)
Finally sweep the answer
#include <cstdio>#include<algorithm>#include<vector>intRead () {intx=0, c=GetChar (); while(c< -) c=GetChar (); while(c> -) x=x*Ten+c- -, c=GetChar (); returnx;}Const intn=100010;intn,m;intet[n*2],enx[n*2],e0[n],ep=2;intsz[n],dep[n],fa[n],pf[n],top[n],id[n],idr[n],idp=0;intq[n][3],vs[n],t[n],tr[262144],ans[n];std::vector<int>_i[n],_d[n];voidF1 (intWintPA) {Dep[w]=dep[fa[w]=pa]+1; SZ[W]=1; for(intI=e0[w];i;i=Enx[i]) { intu=Et[i]; if(U==PA)Continue; F1 (U,W); SZ[W]+=Sz[u]; if(Sz[u]>sz[pf[w]]) pf[w]=u; }}voidF2 (intWintTP) {Idr[id[w]=++idp]=W; TOP[W]=TP; if(Pf[w]) F2 (PF[W],TP); for(intI=e0[w];i;i=Enx[i]) { intu=Et[i]; if(u!=fa[w]&&u!=pf[w]) F2 (u,u); }}voidInsintXintYintz) { inta=top[x],b=Top[y],c; while(a!=b) { if(Dep[a]<dep[b]) c=a,a=b,b=c,c=x,x=y,y=C; _i[id[a]].push_back (z); _d[id[x]].push_back (z); X=fa[a];a=Top[x]; } if(Dep[x]>dep[y]) c=x,x=y,y=C; _i[id[x]].push_back (z); _d[id[y]].push_back (z);}void_ins (intx) { ++T[x]; intw=x+131072; TR[W]=Y; for(w>>=1; w;w>>=1){ inta=w<<1, b=a^1; TR[W]=t[tr[b]]>t[tr[a]]?Tr[b]:tr[a]; }}void_del (intx) { intw=x+131072; if(!--t[x]) tr[w]=0; for(w>>=1; w;w>>=1){ inta=w<<1, b=a^1; TR[W]=t[tr[b]]>t[tr[a]]?Tr[b]:tr[a]; }}intMain () {n=read (); m=read (); for(intI=1; i<n;i++){ intA=read (), b=read (); ET[EP]=b;enx[ep]=e0[a];e0[a]=ep++; ET[EP]=a;enx[ep]=e0[b];e0[b]=ep++; } F1 (1,0); F2 (1,1); for(intI=0; i<m;i++) {q[i][0]=read (); q[i][1]=read (); Vs[i]=q[i][2]=read (); } std::sort (Vs,vs+m); for(intI=0; i<m;i++) {ins (q[i][0],q[i][1],std::lower_bound (vs,vs+m,q[i][2])-vs+1); } for(intI=1; i<=n;i++){ for(intj=0; J<_i[i].size (); j + +) _ins (_i[i][j]); Ans[idr[i]]=tr[1]?vs[tr[1]-1]:0; for(intj=0; J<_d[i].size (); j + +) _del (_d[i][j]); } for(intI=1; i<=n;i++) printf ("%d\n", Ans[i]); return 0;}
bzoj3307: The tail of a rainy day