Transmission Door
Exercises
1 //Minamoto2#include <iostream>3#include <cstdio>4#include <cstring>5#include <vector>6 #definell Long Long7 #defineINF 0x3f3f3f3f3f3f3f3f8 using namespacestd;9 #defineGetc () (p1==p2&& (p2= (p1=buf) +fread (Buf,1,1<<21,stdin), P1==P2)? eof:*p1++)Ten Charbuf[1<< +],*p1=buf,*p2=buf; One intRead () { A #defineNum ch-' 0 ' - CharChBOOLflag=0;intRes; - while(!isdigit (ch=getc ())) the(ch=='-') && (flag=true); - for(Res=num;isdigit (Ch=getc ()); res=res*Ten+num); -(flag) && (res=-res); - #undefNum + returnRes; - } + Const intn=5005; A structNode{ll Y,n;}; Vector<node>F[n]; at intHead[n],next[n],ver[n],tot; -InlinevoidAddintUintv) { -ver[++tot]=v,next[tot]=head[u],head[u]=tot; - } - intc[n],d[n],sz[n],n,q,m; - voidDfsintu) { inll rr,ss,tt;sz[u]=1, F[u].resize (2); -f[u][0].n=0, f[u][0].y=inf,f[u][1].y=c[u]-d[u],f[u][1].n=C[u]; to for(intI=head[u];i;i=Next[i]) { + intv=Ver[i];d FS (v); -F[u].resize (sz[u]+sz[v]+1, (node) {inf,inf}); the for(intj=sz[u];j>=0;--j) * for(intk=0; k<=sz[v];++k) { $rr=f[u][j].n+F[V][K].N,Panax Notoginsengss=f[u][j].y+F[V][K].N, -tt=f[u][j].y+f[v][k].y; the if(RR<=M&&F[U][J+K].N>RR) f[u][j+k].n=RR; + if(SS<=M&&F[U][J+K].Y>SS) f[u][j+k].y=SS; A if(TT<=M&&F[U][J+K].Y>TT) f[u][j+k].y=tt; the } +Vector<node>(). Swap (F[v]); -sz[u]+=Sz[v]; $ } $ } - intMain () { - //freopen ("testdata.in", "R", stdin); theN=read (), M=read (), c[1]=read (), d[1]=read (); - for(intI=2, fa;i<=n;++i)WuyiC[i]=read (), D[i]=read (), fa=read (), add (fa,i); theDfs1); - for(inti=n;i;--i) Wu if(f[1][i].y<=m| | f[1][I].N<=M)returnprintf"%d\n", i),0; - returnPuts"0"),0; About}
cf815c Karen and supermarket