BZOJ 4712: 洪水 挖坑待补
Code:
#include<bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) #define maxn 200001 #define inf 1000000000 #define lson (now<<1) #define rson ((now<<1)|1) using namespace std; char ask[10]; int hd[maxn],to[maxn<<1],nex[maxn<<1],V[maxn],DP[maxn]; int siz[maxn],hson[maxn],top[maxn],ln[maxn],dfn[maxn],fa[maxn],bot[maxn]; int edges,n,Q,tim; void add(int u,int v) { nex[++edges] = hd[u], hd[u] = edges,to[edges] = v; } void dfs1(int u,int ff) { siz[u]=1,fa[u]=ff; for(int i=hd[u];i;i=nex[i]) { int v=to[i]; if(v==ff) continue; dfs1(v,u); siz[u]+=siz[v]; if(siz[v]>siz[hson[u]]) hson[u]=v; } } void dfs2(int u,int tp) { ln[++tim]=u,dfn[u]=tim,top[u]=tp; if(hson[u]) dfs2(hson[u],tp),bot[u]=bot[hson[u]]; else bot[u]=u; for(int i=hd[u];i;i=nex[i]) { int v=to[i]; if(v==fa[u]||v==hson[u]) continue; dfs2(v,v); } } void dfs(int u) { int sum=0; for(int i=hd[u];i;i=nex[i]) { int v=to[i]; if(v==fa[u]||v==hson[u]) continue; dfs(v); sum+=DP[v]; } DP[u]=min(V[u],sum); } int sumv[maxn],lmin[maxn],val[maxn]; void pushup(int now) { sumv[now]=sumv[lson]+sumv[rson]; lmin[now]=min(lmin[lson],sumv[lson]+lmin0[rson]); } void build(int l,int r,int now) { if(l>r) return; if(l==r) { int u=ln[l],sum=0; for(int i=hd[u];i;i=nex[i]) { int v=to[i]; if(v==fa[u]||v==hson[u]) continue; sum+=DP[v]; } if(sum==0) val[u]=V[u]; else val[u]=min(V[u],sum); pushup(now); return; } int mid=(l+r)>>1; build(l,mid,lson); build(mid+1,r,rson); pushup(now); } int query(int l,int r,int now,int L,int R) { if(l>=L&&r<=R) } int main() { setIO("input"); scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&V[i]); for(int i=1,u,v;i<n;++i) { scanf("%d%d",&u,&v),add(u,v),add(v,u); } dfs1(1,0),dfs2(1,1),dfs(1),DP[0]=inf, build(1,n,1); scanf("%d",&Q); while(Q--) { scanf("%s",ask); if(ask[0]=='C') { } if(ask[0]=='Q') { } } return 0; }