#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846
#define mod 1000000007
#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define pb push_back
#define all(c) (c).begin(), (c).end()
const int N = 1e6;
int n, m, q;
vi a, sureWin, ans;
vector<vi> x;
map<int, pair<bool, int>> k;
ii freq[N + 1];
bool win[N + 1], sureLoss[N];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
cin >> n >> m >> q;
a.resize(q);
for (int i = 0; i < q; ++i) {
cin >> a[i];
win[a[i]] = 1;
}
x.resize(n);
for (int w, i = 0; i < n; ++i) {
cin >> w;
x[i].resize(w);
for (int j = 0; j < w; ++j) {
cin >> x[i][j];
if (!win[x[i][j]])
sureLoss[i] = 1;
}
}
for (int i = 0; i < n; ++i) {
if (!sureLoss[i]) {
for (int j = 0; j < x[i].size(); ++j) {
++freq[x[i][j]].first;
freq[x[i][j]].second = i;
// if (k.count(x[i][j])) {
// k[x[i][j]].first = false;
// }
// else {
// k.insert({x[i][j], {true, i}});
// }
}
}
}
// for (auto it = k.begin(); it != k.end(); ++it) {
// if (it->second.first) {
// sureWin.pb(it->second.second);
// }
// }
for (int i = 0; i < N + 1; ++i) {
if (freq[i].first == 1)
sureWin.pb(freq[i].second);
}
sort(sureWin.begin(), sureWin.end());
if (!sureWin.empty())
ans.pb(sureWin[0]);
for (int i = 1; i < sureWin.size(); ++i) {
if (sureWin[i] != sureWin[i - 1])
ans.pb(sureWin[i]);
}
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); ++i)
cout << ans[i] + 1 << " ";
}
Copy