Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX     // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++)
#define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++)
#define per(i, n) for (ll i = ((ll)(n)) - 1; i >= 0; i--)
#define perf(i, n) for (ll i = ((ll)(n)); i > 0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll n, m, ans = 0;
  cin >> n >> m;
  vi k(n), p(m);
  vvi s(n, vi());
  // 入力処理
  rep(i, m) {
    cin >> k[i];
    s[i].resize(k[i]);
    rep(j, k[i]) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  rep(i, m) cin >> p[i];

  // ビット全探索
  for (ll bit = 0; bit < (1LL << (n)); bit++) {
    vector<bool> sw(n, false);
    vector<bool> light(m, false);
    rep(j, n) {
      ll mask = (1LL << j);
      if (bit & mask)
        sw[j] = true;
    }
    rep(i, m) {
      ll cnt = 0;
      rep(j, k[i]) if (sw[s[i][j]]) cnt++;
      if (cnt % 2 == p[i])
        light[i] = true;
    }
    bool tmp = 1;
    rep(i, m) tmp = tmp & light[i];
    ans += tmp;
  }

  // 答えの出力
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX     // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++)
#define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++)
#define per(i, n) for (ll i = ((ll)(n)) - 1; i >= 0; i--)
#define perf(i, n) for (ll i = ((ll)(n)); i > 0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll n, m, ans = 0;
  cin >> n >> m;
  vi k(n), p(m);
  vvi s(m, vi());
  // 入力処理
  rep(i, m) {
    cin >> k[i];
    s[i].resize(k[i]);
    rep(j, k[i]) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  rep(i, m) cin >> p[i];

  // ビット全探索
  for (ll bit = 0; bit < (1LL << (n)); bit++) {
    vector<bool> sw(n, false);
    vector<bool> light(m, false);
    rep(j, n) {
      ll mask = (1LL << j);
      if (bit & mask)
        sw[j] = true;
    }
    rep(i, m) {
      ll cnt = 0;
      rep(j, k[i]) if (sw[s[i][j]]) cnt++;
      if (cnt % 2 == p[i])
        light[i] = true;
    }
    bool tmp = 1;
    rep(i, m) tmp = tmp & light[i];
    ans += tmp;
  }

  // 答えの出力
  cout << ans << endl;
}