[bzoj4027][HEOI2015]兔子与樱花_贪心_树形dp
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> const int maxn=2000010,maxm=maxn<<1; using namespace std; int n,m,pre[maxm],now[maxn],son[maxm],tot,c[maxn],a[maxn],ans; bool ok;char ch; void read(int &x){ for (ok=0,ch=getchar();!isdigit(ch);ch=getchar()) if (ch==‘-‘) ok=1; for (x=0;isdigit(ch);x=x*10+ch-‘0‘,ch=getchar()); if (ok) x=-x; } void add(int a,int b){pre[++tot]=now[a],now[a]=tot,son[tot]=b;} void dfs(int x){ for (int y=now[x];y;y=pre[y]) dfs(son[y]); int cnt=0; for (int y=now[x];y;y=pre[y]) a[++cnt]=c[son[y]]; sort(a+1,a+1+cnt); for (int i=1;i<=cnt;i++){ if