fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. #define pii pair<int, int >
  5. #define f first
  6. #define s second
  7. int arr[301][1100];bool added[301];
  8. signed main()
  9. {
  10. int n, k;cin>>n>>k;
  11. for(int i=0;i<n;i++)
  12. {
  13. for(int j=0;j<110;j++)
  14. {arr[i][j]=0;}
  15. added[i]=false;
  16. }
  17. for(int i=0;i<n;i++)
  18. {
  19. int a;cin>>a;
  20. for(int j=0;j<a;j++)
  21. {
  22. int f;cin>>f;arr[i][f]++;
  23. }
  24. }
  25. queue<int> q;
  26. q.push(0);added[0]=true;
  27. while(!q.empty())
  28. {
  29. int cur=q.front();q.pop();
  30. for(int i=0;i<n;i++)
  31. {
  32. if(added[i]) continue;
  33. int counter=0;
  34. for(int j=0;j<110;j++)
  35. {
  36. counter+=min(arr[cur][j], arr[i][j]);
  37. }
  38. if(counter>=k)
  39. {q.push(i);added[i]=true;}
  40. }
  41. }
  42. int ans=0;
  43. for(int i=0;i<n;i++)
  44. {
  45. if(added[i]) ans++;
  46. }
  47. cout<<ans;
  48. return 0;
  49. }
Success #stdin #stdout 0s 4344KB
stdin
4 2
4 4 6 7 8
4 8 3 0 4
2 0 10
6 1 2 3 0 5 8
stdout
3