天天看點

POJ2443_狀壓的簡單使用

#include<iostream>
#include<algorithm>
#include<bitset>
using namespace std;
const int maxn = 10000 + 10;
bitset<maxn>g[maxn];
int main()
{
  int n, m;
  while (~scanf("%d", &n))
  {
    for (int i = 0; i < maxn; i++)g[i].reset();
    for (int i = 1; i <= n; i++)
    {
      int x, y; scanf("%d", &x);
      for (int j = 1; j <= x; j++)scanf("%d", &y), g[y].set(i);
    }
    scanf("%d", &m);
    while (m--)
    {
      int x, y;
      scanf("%d%d", &x, &y);
      bitset<maxn> t = g[x] & g[y];
      if (t.any())
        puts("Yes");
      else puts("No");
    }
  }
  return 0;
}