Problem p02901 (C++)

Buggy submission (status: Runtime Error):
// fifer a tak luboin
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define ll long long
#define mp make_pair
#define pb push_back
#define s second
#define f first
#define endl "\n"

using namespace std;

const ll inf = 1e14;
const int mod = 998244353;
const int N = (int)100100;
const double eps = 1e-10;
const double pi = acos(-1.0);
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

ll cost[100];
vector<int> g[120];
ll dp[1 << 12];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("lshape.in", "r", stdin);
  // freopen("lshape.out", "w", stdout);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> cost[i] >> x;
    for (int j = 0; j < x; j++) {
      int xx;
      cin >> xx;
      g[i].pb(xx);
    }
  }

  for (int mask = 0; mask < (1 << 12); mask++) {
    dp[mask] = inf;
  }
  dp[0] = 0;

  for (int mask = 0; mask < (1 << n); mask++) {
    for (int i = 0; i < m; i++) {
      int nmask = mask;
      for (int j = 0; j < g[i].size(); j++) {
        if ((nmask & (1 << (g[i][j] - 1))) > 0)
          nmask -= (1 << (g[i][j] - 1));
      }
      dp[mask] = min(dp[mask], dp[nmask] + cost[i]);
    }
  }

  if (dp[(1 << n) - 1] == inf)
    cout << -1 << endl;
  else
    cout << dp[(1 << n) - 1] << endl;

  return 0;
}


Fixed submission:
// fifer a tak luboin
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define ll long long
#define mp make_pair
#define pb push_back
#define s second
#define f first
#define endl "\n"

using namespace std;

const ll inf = 1e14;
const int mod = 998244353;
const int N = (int)100100;
const double eps = 1e-10;
const double pi = acos(-1.0);
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

ll cost[N];
vector<int> g[N];
ll dp[1 << 12];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("lshape.in", "r", stdin);
  // freopen("lshape.out", "w", stdout);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x;
    cin >> cost[i] >> x;
    for (int j = 0; j < x; j++) {
      int xx;
      cin >> xx;
      g[i].pb(xx);
    }
  }

  for (int mask = 0; mask < (1 << 12); mask++) {
    dp[mask] = inf;
  }
  dp[0] = 0;

  for (int mask = 0; mask < (1 << n); mask++) {
    for (int i = 0; i < m; i++) {
      int nmask = mask;
      for (int j = 0; j < g[i].size(); j++) {
        if ((nmask & (1 << (g[i][j] - 1))) > 0)
          nmask -= (1 << (g[i][j] - 1));
      }
      dp[mask] = min(dp[mask], dp[nmask] + cost[i]);
    }
  }

  if (dp[(1 << n) - 1] == inf)
    cout << -1 << endl;
  else
    cout << dp[(1 << n) - 1] << endl;

  return 0;
}