http://poj.org/problem?id=2443
学习一下Bitset
AC代码:
#include <bitset>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 10000 + 5;
bitset<maxn> a[maxn];
int N, Q;
int x, y;
int m, p;
int main() {//清零//for(int i = 0; i < maxn; i++) a[i].reset();scanf("%d",&N);for(int i = 1; i <= N; i++) {scanf("%d",&m);for(int j = 1; j <= m; j++) {scanf("%d",&p);a[p].set(i);}}scanf("%d",&Q);while(Q--) {scanf("%d%d",&x,&y);int flag = 0;if((a[x] & a[y]).any()) flag = 1;if(flag) printf("Yes\n");else printf("No\n");}return 0;
}