注意变换思维,然后就是水题。(如果卡时还可以进一步二分优化。)
#include <stdio.h>long existed[10000][32];
int main(void)
{
int N;
// freopen("poj2443.txt", "r", stdin);
scanf("%d", &N);
int i, j;
for(i=0; i<N; ++i) {
int C, k;
scanf("%d", &C);
for(j=0; j<C; ++j) {
scanf("%d", &k); --k;
existed[k][i >> 5] |= 1 << (i&31);
}
}
int Q;
for(scanf("%d", &Q); Q; --Q) {
int p,q;
scanf("%d%d", &p, &q); --p, --q;
for(i=0; i<32; ++i)
if (existed[p][i] & existed[q][i])
break;
if (i < 32) printf("Yes\n");
else printf("No\n");
}
return 0;
}
2443 | Accepted | 1636K | 1641MS | GCC | 548B | 2014-05-01 02:23:30 |
POJ 2443 - Set Operation
时间: 2024-08-13 21:59:55