Exercises
And HDU5290 very much like, but Hdu hung up, and so on to fill this problem
Not too understand ah ...
I don't know how to read the puzzle.
I'll take a look at it when we do HDU2590.
Code:
//http://blog.csdn.net/aarongzk/article/details/51703297//http://blog.csdn.net/ziqian2000/article/details/52334662#include<bits/stdc++.h>using namespacestd;#definePB Push_back#defineMP Make_pair#defineSe Second#defineFS First#defineLL Long Long#defineCLR (x) memset (x,0,sizeof x)#defineMC (x, y) memcpy (x,y,sizeof (×))#defineSZ (x) ((int) (x). Size ())#definefor (It,c) for (__typeof ((c). Begin ()) it= (c). Begin (); it!= (c). end (); it++)#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1typedef pair<int,int>P;Const Doubleeps=1e-9;Const intmaxn=500100;Const intmod=1e9+7;Const intinf=1e9;intW[MAXN],B[MAXN],HEAD[MAXN];intdown[maxn][ -],up[maxn][ -];intn,d,k,cnt,q;//Down[i][j] Represents the minimum cost of the down-front J-layer in a subtree that is rooted in I//Up[i][j] Represents a subtree in the root of I, the upward J layer is overwritten, and its subtree satisfies the minimum cost of the conditionstructedge{intV,NXT;} EDGE[MAXN*2];voidAddedge (intUintv) {EDGE[CNT].V=v; EDGE[CNT].NXT=Head[u]; Head[u]=cnt++;}voidDfsintUintFA) { if(B[u]) down[u][0]=up[u][0]=W[u]; for(intI=1; i<=d;i++) up[u][i]=W[u]; Up[u][d+1]=INF; for(inti=head[u];i!=-1; i=edge[i].nxt) { intv=edge[i].v; if(V==FA)Continue; DFS (V,U); for(intj=0; j<=d;j++) Up[u][j]=min (up[u][j]+down[v][j],up[v][j+1]+down[u][j+1]); for(intj=d;j>=0; j--) Up[u][j]=min (up[u][j],up[u][j+1]); down[u][0]=up[u][0]; for(intj=1; j<=d;j++) down[u][j]+=down[v][j-1]; for(intj=1; j<=d;j++) Down[u][j]=min (down[u][j-1],down[u][j]); }}intMain () {CNT=0; memset (Head,-1,sizeof(head)); scanf ("%d%d",&n,&d); for(intI=1; i<=n;i++) scanf ("%d",&W[i]); scanf ("%d",&k); for(intI=1; i<=k;i++) {scanf ("%d",&q); B[Q]=1; } for(intI=1; i<=n-1; i++){ intx, y; scanf ("%d%d",&x,&y); Addedge (x, y); Addedge (Y,X); } DFS (1,-1); printf ("%d\n", down[1][0]); return 0;}
BZOJ4557 Reconnaissance Guard