/////home/mohammed/.config/sublime-text-3/Packages/User
/*input
*/
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <list>
#include <set>
using namespace std;
using bin = std::bitset<8>;
#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int int64_t
#define float double
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min({a,b,c})
#define max3(a, b, c) max({a,b,c})
#define min4(a, b, c, d) min({a,b,c,d})
#define max4(a, b, c, d) max({a,b,c,d})
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define ld long double
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define coutArray(a,n) for(int i = 0; i < n; i++){cout << a[i] << " ";};cout << endl;
#define input(type, n) type n; cin>>n;
int32_t main()
{
fast;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
input(int, n);
input(int, m);
int received[m + 1] = {0};
int check[m + 1] = {0};
vector<vector<int>> y;
y.resize(n + 1);
input(int, q);
while (q--) {
input(int, x);
received[x]++;
}
set<int> result;
rep(i, n) {
input(int, w);
int r = 0;
vector<int> v;
rep(e, w) {
input(int, x);
if (received[x] > 0) {
v.pb(x);
r++;
}
}
if (r == w) {
result.insert(i);
rep(e, w) {
check[v[e]]++;
}
y[i] = v;
}
}
vector<int> ans;
for (auto i : result) {
for (auto o : y[i]) {
if (check[o] == 1) {
ans.pb(i + 1);
break;
}
}
}
cout << ans.size() << endl;
for (auto i : ans) {
cout << i << endl;
}
}
Copy