Source Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const int inf = 1e9;
const ll infll = 1e18;
const int M = 1000000007;
const int N = 1e6;

int n, m, q, a[N], fr[N+1];

int main(){	
	scanf("%d%d%d",&n,&m,&q);
	for (int i = 0; i < q; ++i){
		scanf("%d", &a[i]);
		++fr[a[i]];
	}
	vector<vector<int>> v;
	for (int i = 0, w; i < n; ++i){
		scanf("%d", &w);
		vector<int> tmp;
		bool bad = 0;
		for (int j = 0, x; j < w; ++j){
			scanf("%d", &x);
			if(fr[x] == 0) bad = 1;
			tmp.pb(x);
		}
		if(bad) tmp.clear();
		v.pb(tmp);
	}
	memset(fr, 0, sizeof fr);
	vector<int> ans;
	for (int i = 0; i < v.size(); ++i){
		for(auto x : v[i]){
			++fr[x];
		}
	}
	for (int i = 0; i < v.size(); ++i){
		for(auto x : v[i]){
			if(fr[x] == 1){
				ans.pb(i+1);
				break;
			}
		}
	}
	sort(all(ans));
	printf("%d\n",ans.size());
	for(auto x : ans) printf("%d\n", x);
	puts("");



}
Copy
Projects Hambubger
GNU G++17
705 ms
42.6 MB
Accepted