Problem p02901 (C++)

Buggy submission (status: Runtime Error):
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author parsa bahrami
 */

#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sz(x) (ll) x.size()
#define jjoin(x)                                                               \
  for (auto i : x)                                                             \
    cout << i << endl;
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define Mp make_pair
#define sep ' '
#define error(x) cerr << #x << " = " << x << endl
#define fast_io                                                                \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define set_random                                                             \
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define kill(x) return cout << x << endl, 0;
#define Hkill(x)                                                               \
  cout << x << endl;                                                           \
  exit(0);
#define endl '\n'

ll poww(ll a, ll b, ll md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 2e5 + 10;
const ll MAXA = 101;
const ll INF = 8e18;
const ll MOD = 998244353; // 1e9 + 7
const ld PI = 4 * atan((ld)1);
const ll LOG = 15;
ll cost[MAXA], SUB[MAXA][MAXA], dp[1LL << LOG], T[MAXA];

int main() {
  fast_io;
  set_random;
  ll n, m;
  cin >> n >> m;
  for (ll i = 0; i < m; i++) {
    ll b, mask = 0;
    cin >> cost[i] >> b;
    for (ll j = 0; j < b; j++) {
      cin >> SUB[i][j];
      mask |= (1LL << (SUB[i][j] - 1));
    }
    T[i] = mask;
  }
  fill(dp, dp + (1LL << LOG), INF);
  dp[0] = 0;
  for (ll i = 0; i < m; i++) {
    for (ll mask = 0; mask < (1LL << n); mask++) {
      dp[mask | T[i]] = min(dp[mask | T[i]], dp[mask] + cost[i]);
    }
  }
  cout << (dp[(1LL << n) - 1] == INF ? -1 : dp[(1LL << n) - 1]) << endl;
  return 0;
}


Fixed submission:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author parsa bahrami
 */

#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sz(x) (ll) x.size()
#define jjoin(x)                                                               \
  for (auto i : x)                                                             \
    cout << i << endl;
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define Mp make_pair
#define sep ' '
#define error(x) cerr << #x << " = " << x << endl
#define fast_io                                                                \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define set_random                                                             \
  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define kill(x) return cout << x << endl, 0;
#define Hkill(x)                                                               \
  cout << x << endl;                                                           \
  exit(0);
#define endl '\n'

ll poww(ll a, ll b, ll md) {
  return (!b ? 1
             : (b & 1 ? a * poww(a * a % md, b / 2, md) % md
                      : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 2e5 + 10;
const ll MAXA = 1010;
const ll INF = 8e18;
const ll MOD = 998244353; // 1e9 + 7
const ld PI = 4 * atan((ld)1);
const ll LOG = 15;
ll cost[MAXA], SUB[MAXA][MAXA], dp[1LL << LOG], T[MAXA];

int main() {
  fast_io;
  set_random;
  ll n, m;
  cin >> n >> m;
  for (ll i = 0; i < m; i++) {
    ll b, mask = 0;
    cin >> cost[i] >> b;
    for (ll j = 0; j < b; j++) {
      cin >> SUB[i][j];
      mask |= (1LL << (SUB[i][j] - 1));
    }
    T[i] = mask;
  }
  fill(dp, dp + (1LL << LOG), INF);
  dp[0] = 0;
  for (ll i = 0; i < m; i++) {
    for (ll mask = 0; mask < (1LL << n); mask++) {
      dp[mask | T[i]] = min(dp[mask | T[i]], dp[mask] + cost[i]);
    }
  }
  cout << (dp[(1LL << n) - 1] == INF ? -1 : dp[(1LL << n) - 1]) << endl;
  return 0;
}