Problem p02837 (C++)

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x) cout << #x << " = " << (x) << endl; // debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << res << endl;
#define ALL(a) (a).begin(), (a).end()
#define RANGE(a, l, r) (a).begin() + (l), (a).begin() + (r)

int main() {
  int n;
  cin >> n;
  vector<vector<pair<int, bool>>> info(n + 1);
  FOR(i, 1, n) {
    int a;
    cin >> a;
    FOR(j, 1, a) {
      int x;
      bool y;
      cin >> x >> y;
      info[i].push_back(make_pair(x, y));
    }
  }

  int res = 0;
  for (int bit = 0; bit < (1 << (n)); bit++) {
    vector<bool> memo(n + 1, false);
    bool isok = true;
    FOR(digit, 1, n) {
      if (bit & (1 << (digit - 1))) {
        memo[digit] = true;
      }
    }
    FOR(digit, 1, n) {
      if (bit & (1 << (digit - 1))) {
        FOR(i, 0, info[digit].size() - 1) {
          if (memo[info[digit][i].first] != info[digit][i].second) {
            isok = false;
          }
        }
      }
    }

    if (!isok) {
      continue;
    }

    int cnt = 0;
    FOR(i, 1, n) {
      if (memo[i]) {
        cnt++;
      }
    }
    res = max(res, cnt);
  }
  pv(res) return (0);
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x) cout << #x << " = " << (x) << endl; // debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << res << endl;
#define ALL(a) (a).begin(), (a).end()
#define RANGE(a, l, r) (a).begin() + (l), (a).begin() + (r)

int main() {
  int n;
  cin >> n;
  vector<vector<pair<int, bool>>> info(n + 1);
  FOR(i, 1, n) {
    int a;
    cin >> a;
    FOR(j, 1, a) {
      int x;
      bool y;
      cin >> x >> y;
      info[i].push_back(make_pair(x, y));
    }
  }

  int res = 0;
  for (int bit = 0; bit < (1 << (n)); bit++) {
    vector<bool> memo(n + 1, false);
    bool isok = true;
    FOR(digit, 1, n) {
      if (bit & (1 << (digit - 1))) {
        memo[digit] = true;
      }
    }
    FOR(digit, 1, n) {
      if (bit & (1 << (digit - 1))) {
        FOR(i, 0, SZ(info[digit]) - 1) {
          if (memo[info[digit][i].first] != info[digit][i].second) {
            isok = false;
          }
        }
      }
    }

    if (!isok) {
      continue;
    }

    int cnt = 0;
    FOR(i, 1, n) {
      if (memo[i]) {
        cnt++;
      }
    }
    res = max(res, cnt);
  }
  pv(res) return (0);
}