Problem p02901 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

#define int long long
#define ll long long
#define F first
#define S second
#define make make_pair
#define pb push_back
#define sz(x) (ll)(x.size())
#define all(x) x.begin(), x.end()

using namespace std;

typedef long double ld;

const int MOD = (int)1e9 + 7;
const int N = (int)1e5 * 5 + 22;
const ll INF = (ll)1e18;
const double eps = (double)1e-6;

int n, m, a[N], b[N], c[100][1111];
int dp[N];

signed main() {
#ifdef Maga
  freopen("input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int mask = 0; mask <= (1 << n) - 1; ++mask) {
    dp[mask] = INF;
  }
  dp[0] = 0;
  for (int i = 1; i <= m; ++i) {
    cin >> a[i] >> b[i];
    for (int j = 1; j <= b[i]; ++j) {
      cin >> c[i][j];
    }
  }
  for (int i = 1; i <= m; ++i) {
    for (int mask = 0; mask <= (1 << (n)) - 1; ++mask) {
      int x = mask;
      for (int j = 1; j <= b[i]; ++j) {
        x = (x | (1 << (c[i][j] - 1)));
      }
      dp[x] = min(dp[mask] + a[i], dp[x]);
    }
  }
  if (dp[(1 << n) - 1] >= INF)
    cout << -1;
  else
    cout << dp[(1 << (n)) - 1];

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

#define int long long
#define ll long long
#define F first
#define S second
#define make make_pair
#define pb push_back
#define sz(x) (ll)(x.size())
#define all(x) x.begin(), x.end()

using namespace std;

typedef long double ld;

const int MOD = (int)1e9 + 7;
const int N = (int)1e5 * 5 + 22;
const ll INF = (ll)1e18;
const double eps = (double)1e-6;

int n, m, a[N], b[N], c[1111][1111];
int dp[N];

signed main() {
#ifdef Maga
  freopen("input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int mask = 0; mask <= (1 << n) - 1; ++mask) {
    dp[mask] = INF;
  }
  dp[0] = 0;
  for (int i = 1; i <= m; ++i) {
    cin >> a[i] >> b[i];
    for (int j = 1; j <= b[i]; ++j) {
      cin >> c[i][j];
    }
  }
  for (int i = 1; i <= m; ++i) {
    for (int mask = 0; mask <= (1 << (n)) - 1; ++mask) {
      int x = mask;
      for (int j = 1; j <= b[i]; ++j) {
        x = (x | (1 << (c[i][j] - 1)));
      }
      dp[x] = min(dp[mask] + a[i], dp[x]);
    }
  }
  if (dp[(1 << n) - 1] >= INF)
    cout << -1;
  else
    cout << dp[(1 << (n)) - 1];

  return 0;
}