#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
using namespace std;
using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> adjList;
typedef pair<int, pair<int, int>> iii;
typedef vector<unsigned int> vui;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vi vm;
typedef vector<vm> Mat;
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#else
// freopen("outofplace.in", "r", stdin);
// freopen("outofplace.out", "w", stdout);
#endif
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;
int n, m; cin >> n >> m;
vi received(m);
int q; cin >> q;
while (q--) {
int x; cin >> x; --x;
received[x] = 1;
}
vector<vi> projects(n);
vi win(n);
vi how_many(m);
for (int i = 0; i < n; ++i) {
int w; cin >> w;
projects[i].resize(w);
win[i] = 1;
for (int &x : projects[i]) {
cin >> x; --x;
win[i] &= received[x];
}
if (win[i]) {
for (int &x : projects[i]) {
++how_many[x];
}
}
}
vi ans;
for (int i = 0; i < n; ++i) {
bool f = false;
if (win[i]) {
for (int &x : projects[i]) {
f |= how_many[x] == 1;
}
}
if (f) ans.push_back(i + 1);
}
cout << sz(ans) << '\n';
for (int &x : ans) cout << x << ' ';
cout << '\n';
return 0;
}
Copy