#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
int main(){
FAST
int n, m, q;
cin >> n >> m >> q;
int rec[m];
mm(rec);
for(int i = 0; i < q; i++){
int b;
cin >> b;
b--;
rec[b] = 1;
}
vector<int> proj[n];
int cnt[m];
mm(cnt);
bool ok[n];
vector<int> ans;
for(int i = 0; i < n; i++){
int k; cin >> k;
proj[i].resize(k);
ok[i] = 1;
for(int j = 0; j < k; j++){
cin >> proj[i][j];
proj[i][j]--;
if(!rec[proj[i][j]]){
ok[i] = 0;
}
}
if(ok[i]){
for(int j = 0; j < k; j++){
cnt[proj[i][j]]++;
}
}
}
for(int i = 0; i < n; i++){
bool has = 0;
if(ok[i]){
for(int j = 0; j < proj[i].size(); j++){
if(cnt[proj[i][j]] == 1){
has = 1;
break;
}
}
}
if(has){
ans.pb(i + 1);
}
}
cout << ans.size() << endl;
for(int i = 0; i < ans.size(); i++){
cout << ans[i] << " ";
}
return 0;
}
Copy