fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using int64 = long long;
  4. int main() {
  5. int n, t;
  6. cin >> n >> t;
  7. vector<int64> masks(n);
  8. for (int i = 0; i < t; ++i) {
  9. int k;
  10. cin >> k;
  11. vector<int> a(k);
  12. for (int &j : a) {
  13. cin >> j; --j;
  14. }
  15. sort(a.begin(), a.end());
  16. if (a[0] == 0) {
  17. for (int j : a) masks[j] |= (1LL << i);
  18. } else {
  19. int64 mask = 0;
  20. for (int j : a) mask |= masks[j];
  21. for (int j : a) masks[j] = mask;
  22. }
  23. }
  24. for (int i = 0; i < n; ++i) if (masks[i] == masks[0]) cout << i + 1 << '\n';
  25. return 0;
  26. }
Success #stdin #stdout 0s 4436KB
stdin
5
3
2 1 3
2 2 1
4 2 1 4 5
stdout
1