Source Code
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int n, m, a[1000000], freq[1000001] = {}, q, ans = 0, b[1000000] = {}, freq2[1000001] = {};
	vector <int> v[1000000];
	cin >> n >> m;
	cin >> q;
	for(int i = 0; i < q; ++i){
		cin >> a[i];
		++freq[a[i]];
	}
	for(int i = 0, x, y; i < n; ++i){
		cin >> x;
		bool u = 1;
		for(int j = 0; j < x; ++j){
			cin >> y;
			v[i].push_back(y);
			if(!freq[y]){
				u = false;
			}
		}
		if(u){
			for(int j = 0; j < v[i].size(); ++j){
				++freq2[v[i][j]];
			}
		}
	}
	for(int i = 0; i < n; ++i){
		bool u = true;
		int counter = 0;
		for(int j = 0; j < v[i].size(); ++j){
			if(!freq[v[i][j]]){
				u = false;
			}
			if(freq2[v[i][j]] > 1){
				++counter;
			}
		}
		if(u){
			if(counter != v[i].size()){
				++ans;
				b[i] = 1;
			}
		}
	}
	cout << ans << endl;
	for(int i = 0; i < n; ++i){
		if(b[i]){
			cout << i + 1 << endl;
		}
	}
	return 0;
}
Copy
Projects azoz
GNU G++17
1417 ms
57.1 MB
Accepted