Source Code
#include <bits/stdc++.h>
using namespace std;
    
int main (){

  #ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1","r",stdin);
  #endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m, q;
  cin >> n >> m >> q;
  int w[m + 1] = {};
  while (q--) {
    int x;
    cin >> x;
    w[x] = 1;
  }
  vector<int> proj[n];
  int wins[m + 1] = {}, won[n + 1];
  for (int i = 0; i < n; ++i) {
    int s;
    cin >> s;
    won[i] = 1;
    while (s--) {
      int x;
      cin >> x;
      proj[i].push_back(x);
      won[i] &= w[x];
    }
    if (won[i]) {
      for (int j : proj[i]) {
        ++wins[j];
      }
    }
  }
  vector<int> ans;
  for (int i = 0; i < n; ++i) {
    bool ok = 0;
    for (int j : proj[i]) {
      ok |= wins[j] == 1;
    }
    if (ok && won[i]) {
      ans.push_back(i + 1);
    }
  }
  cout << ans.size() << "\n";
  for (int i : ans) {
    cout << i << " ";
  }

  return 0;
}
Copy
Projects SuhaibSawalha1
GNU G++17
428 ms
48.0 MB
Accepted