博主又来水blog啦
博主上一篇blog好像有提到这个bitset,其实那是博主并不是很懂,所以向Matchperson学习了这个操作。
题目概述
给定
n
个集合。
在提出
解题思路
读入的时候标记一下,然后并起来判断有没有1。
所以就可以bitset乱搞。
bitset大法好啊。
#include<cstdio>
#include<bitset>
using namespace std;
bitset<1005> s[10005];
int n,Q;
inline int _read(){
int num=0;char ch=getchar();
while (ch<'0'||ch>'9') ch=getchar();
while (ch>='0'&&ch<='9') num=num*10+ch-48,ch=getchar();
return num;
}
int main(){
freopen("exam.in","r",stdin);
freopen("exam.out","w",stdout);
n=_read();
for (int i=1;i<=n;i++){
int x=_read();
while (x--) s[_read()][i-1]=1;
}
Q=_read();
while(Q--){
int x=_read(),y=_read();
if ((s[x]&s[y]).any()) printf("Yes\n");else printf("No\n");
}
return 0;
}