#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #define ll long long #define INF 0x7fffffff #define re register #define int long long
intdfs(int u) { if(u > n - m) { f[u][1] = v[u]; return1; } int tj = 0,k; for(int i = d[u]; i; i = e[i].nex) { int v = e[i].to; k = dfs(v); tj += k; for(int l = tj; l > 0; l--) for(int j = k; j >= 0; j--) f[u][l] = max(f[u][l],f[u][l - j] + f[v][j] - e[i].w); } return tj; }
signedmain() { n = read(); m = read(); for(int i = 1; i <= n - m; i++) { k = read(); for(int j = 1; j <= k; j++) y = read(), z = read(), add(i,y,z); } for(int i = n - m + 1; i <= n; i++) v[i] = read(),sum += v[i]; memset(f,-100,sizeof(f)); for(int i = 1; i <= n; i++) f[i][0] = 0; dfs(1); for(int i = m; i >= 0; i--) if(f[1][i] >= 0) { printf("%d\n",i); return0; } return0; }