Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout << #x << " = " << (x) << " (L" << LINE << ")" << endl;
#define vdeb(x)                                                                \
  {                                                                            \
    cout << #x << " = { ";                                                     \
    rep(i, x.size()) cout << x[i] << ' ';                                      \
    cout << '}' << " (L" << LINE << ")" << endl;                               \
  }
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
  ll N, M;
  cin >> N >> M;
  vllvll s(M, vll(0));
  ll tmp;
  ll k;
  rep(i, 0, M) {
    cin >> k;
    rep(j, 0, k) {
      cin >> tmp;
      --tmp;
      s[i].push_back(tmp);
    }
  }
  vll p(M);
  rep(i, 0, M) { cin >> p[i]; }

  ll ans = 0;
  rep(bit, 0, 1 << N) { // each pattern
    vll switches(M, 0);
    rep(i, 0, N) { // filter
      if (bit & 1 << i) {
        switches[i] = 1;
      }
    }
    bool flg = true;
    rep(i, 0, M) { // each bulb
      ll sm = 0;
      rep(j, 0, s[i].size()) { // each connected switch
        sm += switches[s[i][j]];
      }
      if (sm % 2 != p[i]) {
        flg = false;
        break;
      }
    }
    if (flg) {
      ++ans;
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout << #x << " = " << (x) << " (L" << LINE << ")" << endl;
#define vdeb(x)                                                                \
  {                                                                            \
    cout << #x << " = { ";                                                     \
    rep(i, x.size()) cout << x[i] << ' ';                                      \
    cout << '}' << " (L" << LINE << ")" << endl;                               \
  }
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;

int main() {
  ll N, M;
  cin >> N >> M;
  vllvll s(M, vll(0));
  ll tmp;
  ll k;
  rep(i, 0, M) {
    cin >> k;
    rep(j, 0, k) {
      cin >> tmp;
      --tmp;
      s[i].push_back(tmp);
    }
  }
  vll p(M);
  rep(i, 0, M) { cin >> p[i]; }

  ll ans = 0;
  rep(bit, 0, 1 << N) { // each pattern
    vll switches(N, 0);
    rep(i, 0, N) { // filter
      if (bit & 1 << i) {
        switches[i] = 1;
      }
    }
    bool flg = true;
    rep(i, 0, M) { // each bulb
      ll sm = 0;
      rep(j, 0, s[i].size()) { // each connected switch
        sm += switches[s[i][j]];
      }
      if (sm % 2 != p[i]) {
        flg = false;
        break;
      }
    }
    if (flg) {
      ++ans;
    }
  }

  cout << ans << endl;
}