#include<bits/stdc++.h>
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=2000005;
inline void read(int &x)
{
x=0;char ch=getchar();
while(ch<'0'||ch>'9')ch=getchar();
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
}
vector<int> G[N];
int n,m,c[N],ans;
bool cmp(int a,int b)
{
return c[a]<c[b];
}
void dfs(int u)
{
for(int i=0;i<G[u].size();i++)
dfs(G[u][i]);
sort(G[u].begin(),G[u].end(),cmp);
c[u]+=G[u].size();//
for(int i=0;i<G[u].size();i++){
int v=G[u][i];
if(c[u]+c[v]-1<=m){
ans++;c[u]+=c[v]-1;
}
else break;
}
}
int main()
{
read(n);read(m);
for(int i=0;i<n;i++)read(c[i]);
for(int i=0;i<n;i++){
int x,v;read(x);
while(x--){
read(v);
G[i].push_back(v);
}
}
dfs(0);
printf("%d",ans);
return 0;
}
BZOJ4027 [HEOI2015]兔子与樱花 树形dp+贪心
猜你喜欢
转载自blog.csdn.net/Wolf_Reiser/article/details/78573751
今日推荐
周排行