①初始化 注意<>内,见代码(字符串是高位往低位读,数字低位往高位读)
②增改:set(),reset(), set(i),set(i,1) flip(),flip(i)反转
③查:支持【】 count()/any()是否有1 none() 和all()检查全0或全1
④改输出类型 .to_ullong() .to_string()
#include<cstdio>
#include<bitset>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
bitset<1005>s[500005];//每个数,集合是否出现用二进制串 判断
bitset<1005>q;//不同于其他stl,<>内规定大小
bitset<1005>q2((string)"100001") ;//string初始化前面补0
bitset<1005>q3(15);//unsigned long long初始化
int main()
{
int n,k,m,a,b;
while(~scanf("%d",&n)){
for(int i=0;i<n;i++){
scanf("%d",&k);
while(k--){
scanf("%d",&a);
s[a].set(i,1);//也可用数组
}
}
scanf("%d",&m);
while(m--){
scanf("%d %d",&a,&b);
if((s[a]&s[b]).count()){ //.any也可判断是否有1
printf("Yes\n");
}
else printf("No\n");
}
}
}