Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d", &x)
#define rd2(x, y) scanf("%d %d", &x, &y)
#define rd3(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define rl(x) scanf("%lld", &x)
#define rl2(x, y) scanf("%lld %lld", &x, &y)
#define rl3(x, y, z) scanf("%lld %lld %lld", &x, &y, &z)
#define wd(x) printf("%d", x)
#define wd2(x, y) printf("%d %d", x, y)
#define wl(x) printf("%lld", x)
#define wl2(x, y) printf("%lld %lld", x, y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it, a)                                                            \
  for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define fast_cin()                                                             \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define fr(i, s, e) for (int i = s; i < e; i++)
#define frl(i, s, e) for (ll i = s; i < e; i++)
#define frr(i, s, e) for (int i = s - 1; i >= e; i--)
#define frv(i, a) for (int i = 0; i < (int)a.size(); i++)
#define frvr(i, a) for (int i = a.size() - 1; i >= 0; i--)
#define tr(i, a) for (typeof(a.begin()) i = a.begin(); i != a.end(); i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
map<ll, VL> mp;
void solve() {
  ll n, m;
  rl2(n, m);
  fr(i, 0, m) {
    ll k;
    rl(k);
    fr(j, 0, k) {
      ll s;
      rl(s);
      mp[s - 1].PB(j);
    }
  }
  VL p(m);
  fr(i, 0, m) rl(p[i]);
  ll pset = pow(2, n);
  ll ct = 0;
  fr(i, 0, pset) {
    VL b(m, 0);
    fr(j, 0, n) {
      if (i & (1 << j)) {
        VL tmp = mp[j];
        fr(x, 0, SZ(tmp)) { b[tmp[x]]++; }
      }
    }
    ll flag = 1;
    fr(j, 0, m) {
      if (p[j] != (b[j] % 2))
        flag = 0;
    }
    if (flag)
      ct++;
  }
  wl(ct);
  NL;
  return;
}
int main() {
  // sstd::ios::sync_with_stdio(false); cin.tie(NULL);
  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d", &x)
#define rd2(x, y) scanf("%d %d", &x, &y)
#define rd3(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define rl(x) scanf("%lld", &x)
#define rl2(x, y) scanf("%lld %lld", &x, &y)
#define rl3(x, y, z) scanf("%lld %lld %lld", &x, &y, &z)
#define wd(x) printf("%d", x)
#define wd2(x, y) printf("%d %d", x, y)
#define wl(x) printf("%lld", x)
#define wl2(x, y) printf("%lld %lld", x, y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it, a)                                                            \
  for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define fast_cin()                                                             \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define fr(i, s, e) for (int i = s; i < e; i++)
#define frl(i, s, e) for (ll i = s; i < e; i++)
#define frr(i, s, e) for (int i = s - 1; i >= e; i--)
#define frv(i, a) for (int i = 0; i < (int)a.size(); i++)
#define frvr(i, a) for (int i = a.size() - 1; i >= 0; i--)
#define tr(i, a) for (typeof(a.begin()) i = a.begin(); i != a.end(); i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
map<ll, VL> mp;
void solve() {
  ll n, m;
  rl2(n, m);
  fr(i, 0, m) {
    ll k;
    rl(k);
    fr(j, 0, k) {
      ll s;
      rl(s);
      mp[s - 1].PB(i);
    }
  }
  VL p(m);
  fr(i, 0, m) rl(p[i]);
  ll pset = pow(2, n);
  ll ct = 0;
  fr(i, 0, pset) {
    VL b(m, 0);
    fr(j, 0, n) {
      if (i & (1 << j)) {
        VL tmp = mp[j];
        fr(x, 0, SZ(tmp)) { b[tmp[x]]++; }
      }
    }
    ll flag = 1;
    fr(j, 0, m) {
      if (p[j] != (b[j] % 2))
        flag = 0;
    }
    if (flag)
      ct++;
  }
  wl(ct);
  NL;
  return;
}
int main() {
  // sstd::ios::sync_with_stdio(false); cin.tie(NULL);
  solve();
  return 0;
}