Source Code
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 1000010;

int n , m;

bool good[N] , bad[N];

vector< int > arr[N];

int frq[N] , q ;


int main(){
	scanf("%d%d",&n,&m);
	scanf("%d",&q);
	for(int a , i = 0 ;i < q;i++){
		scanf("%d",&a);
		good[a] = true;
	}
	for(int sz ,i = 0 ;i < n;i++){
		scanf("%d",&sz);
		arr[i].resize(sz);
		for(int j = 0 ; j < sz;j++){
			scanf("%d",&arr[i][j]);
			if(!good[arr[i][j]])
				bad[i] = true;
		}
		if(!bad[i]){
			for(int j = 0 ;j < sz;j++){
				frq[arr[i][j]]++;
			}
		}
	}
	vector< int > ans;
	bool in;
	for(int i = 0 ;i < n;i++){
		in = false;
		for(int j = 0 ;j < (int)arr[i].size();j++){
			if(frq[arr[i][j]] == 1)
				in = true;
		}
		if(!bad[i] && in)
			ans.push_back(i);
	}
	printf("%d\n",(int)ans.size());
	for(int i = 0 ;i < (int)ans.size();i++){
		printf("%d ",ans[i] + 1);
	}
	puts("");

	return 0;
}
Copy
Projects Kilani
GNU G++17
584 ms
39.5 MB
Accepted