1 /**************************************************************
2 Problem: 4027
3 User: Tunix
4 Language: C++
5 Result: Accepted
6 Time:5096 ms
7 Memory:105224 kb
8 ****************************************************************/
9
10 //BZOJ 4027
11 #include<vector>
12 #include<cstdio>
13 #include<cstring>
14 #include<cstdlib>
15 #include<iostream>
16 #include<algorithm>
17 #define rep(i,n) for(int i=0;i<n;++i)
18 #define F(i,j,n) for(int i=j;i<=n;++i)
19 #define D(i,j,n) for(int i=j;i>=n;--i)
20 #define pb push_back
21 using namespace std;
22 typedef long long LL;
23 inline int getint(){
24 int r=1,v=0; char ch=getchar();
25 for(;!isdigit(ch);ch=getchar()) if(ch==‘-‘)r=-1;
26 for(; isdigit(ch);ch=getchar()) v=v*10+ch-‘0‘;
27 return r*v;
28 }
29 const int N=2000010;
30 /*******************template********************/
31 int n,m,c[N],a[N],ans;
32 vector<int>G[N],V[N];
33 void dfs(int x){
34 a[x]=c[x];
35 rep(i,G[x].size()){
36 dfs(G[x][i]);
37 a[x]++;
38 V[x].pb(a[G[x][i]]);
39 }
40 if (V[x].size()) sort(V[x].begin(),V[x].end());
41 rep(i,V[x].size()){
42 if (a[x]+V[x][i]-1>m) break;
43 a[x]=a[x]+V[x][i]-1;
44 ans++;
45 }
46 }
47 int main(){
48 #ifndef ONLINE_JUDGE
49 freopen("4027.in","r",stdin);
50 freopen("4027.out","w",stdout);
51 #endif
52 n=getint(); m=getint();
53 rep(i,n) c[i]=getint();
54 rep(i,n){
55 int x=getint();
56 F(j,1,x){
57 int y=getint();
58 G[i].pb(y);
59 }
60 }
61 dfs(0);
62 printf("%d\n",ans);
63 return 0;
64 }