Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

vector <ll> p(1005);
vector <ll> g[1005];
unordered_map <ll, bool> vis;
unordered_map <ll, ll> dp;
ll n, m;

ll solve(ll tt){
    ll ind = tt/(1e15);
    ll x = tt%(1e15);
    if(ind==m){
        vl xx;
        ll z = x;
        for(int j=n-1; j>=0; j--){
            ll t = xpow(12, j);
            if(z/t){
                xx.pb(1);
            }
            else{
                xx.pb(0);
            }
            z%=t;
        }
        bool check = 1;
        for(auto j:xx){
            if(j==0){
                check = 0;
            }
        }
        if(check){
            return 0;
        }
        else{
            return (ll)(1e9);
        }
    }
    if(vis[{ind,x}]){
        return dp[{ind, x}];
    }
    vis[{ind, x}]=1;
    ll v = p[ind];
    vl xx;
    ll z = x;
    for(int j=n-1; j>=0; j--){
        ll t = xpow(12, j);
        if(z/t){
            xx.pb(1);
        }
        else{
            xx.pb(0);
        }
        z%=t;
    }
    reverse(all(xx));
    vl y = xx;
    for(auto j:g[ind]){
        y[j]=1;
    }
    ll yy = 0;
    for(ll i=0; i<y.size(); i++){
        if(y[i]==1){
            yy += xpow(12, i);
        }
    }
    return dp[{ind, x}]=min(v+solve( (ind+1)*1e15 + y), solve( (ind+1)*1e15 + x));
}

int main(){
    fast();

/* you get what you work for not what you wish for */
    scanf("%lld%lld", &n, &m);
    for(int i=0; i<m; i++){
        scanf("%lld", &p[i]);
        ll sz;
        scanf("%lld", &sz);
        for(int j=0; j<sz; j++){
            ll x;
            scanf("%lld", &x);
            x--;
            g[i].pb(x);
        }
    }
    ll y = solve(0);
    if(y>=1e9){
        out(-1);
    }
    else{
        out(y);
    }
}

Compiler output:
a.cc: In function 'll solve(ll)':
a.cc:53:14: error: invalid operands of types 'll' {aka 'long long int'} and 'double' to binary 'operator%'
   53 |     ll x = tt%(1e15);
      |            ~~^~~~~~~
      |            |   |
      |            |   double
      |            ll {aka long long int}
a.cc:80:11: error: no match for 'operator[]' (operand types are 'std::unordered_map<long long int, bool>' and '<brace-enclosed initializer list>')
   80 |     if(vis[{ind,x}]){
      |           ^
In file included from /usr/include/c++/14/unordered_map:41,
                 from /usr/include/c++/14/functional:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/unordered_map.h:987:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type&) [with _Key = long long int; _Tp = bool; _Hash = std::hash<long long int>; _Pred = std::equal_to<long long int>; _Alloc = std::allocator<std::pair<const long long int, bool> >; mapped_type = bool; key_type = long long int]'
  987 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/unordered_map.h:987:34: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::unordered_map<long long int, bool>::key_type&' {aka 'const long long int&'}
  987 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/unordered_map.h:991:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&&) [with _Key = long long int; _Tp = bool; _Hash = std::hash<long long int>; _Pred = std::equal_to<long long int>; _Alloc = std::allocator<std::pair<const long long int, bool> >; mapped_type = bool; key_type = long long int]'
  991 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/unordered_map.h:991:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::unordered_map<long long int, bool>::key_type&&' {aka 'long long int&&'}
  991 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:81:18: error: no match for 'operator[]' (operand types are 'std::unordered_map<long long int, long long int>' and '<brace-enclosed initializer list>')
   81 |         return dp[{ind, x}];
      |                  ^
/usr/include/c++/14/bits/unordered_map.h:987:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type&) [with _Key = long long int; _Tp = long long int; _Hash = std::hash<long long int>; _Pred = std::equal_to<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >; mapped_type = long long int; key_type = long long int]'
  987 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/unordered_map.h:987:34: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::unordered_map<long long int, long long int>::key_type&' {aka 'const long long int&'}
  987 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/unordered_map.h:991:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&&) [with _Key = long long int; _Tp = long long int; _Hash = std::hash<long long int>; _Pred = std::equal_to<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >; mapped_type = long long int; key_type = long long int]'
  991 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/unordered_map.h:991:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::unordered_map<long long int, long long int>::key_type&&' {aka 'long long int&&'}
  991 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:83:8: error: no match for 'operator[]' (operand types are 'std::unordered_map<long long int, bool>' and '<brace-enclosed initializer list>')
   83 |     vis[{ind, x}]=1;
      |        ^
/usr/include/c++/14/bits/unordered_map.h:987:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type&) [with _Key = long long int; _Tp = bool; _Hash = std::hash<long long int>; _Pred = std::equal_to<long long int>; _Alloc = std::allocator<std::pair<const long long int, bool> >; mapped_type = bool; key_type = long long int]'
  987 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/unordered_map.h:987:34: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::unordered_map<long long int, bool>::key_type&' {aka 'const long long int&'}
  987 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/unordered_map.h:991:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&&) [with _Key = long long int; _Tp = bool; _Hash = std::hash<long long int>; _Pred = std::equal_to<long long int>; _Alloc = std::allocator<std::pair<const long long int, bool> >; mapped_type = bool; key_type = long long int]'
  991 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/unordered_map.h:991:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::unordered_map<long long int, bool>::key_type&&' {aka 'long long int&&'}
  991 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:108:14: error: no match for 'operator[]' (operand types are 'std::unordered_map<long long int, long long int>' and '<brace-enclosed initializer list>')
  108 |     return dp[{ind, x}]=min(v+solve( (ind+1)*1e15 + y), solve( (ind+1)*1e15 + x));
      |              ^
/usr/include/c++/14/bits/unordered_map.h:987:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type&) [with _Key = long long int; _Tp = long long int; _Hash = std::hash<long long int>; _Pred = std::equal_to<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >; mapped_type = long long int; key_type = long long int]'
  987 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/unordered_map.h:987:34: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::unordered_map<long long int, long long int>::key_type&' {aka 'const long long int&'}
  987 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/unordered_map.h:991:7: note: candidate: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::mapped_type& std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&&) [with _Key = long long int; _Tp = long long int; _Hash = std::hash<long long int>; _Pred = std::equal_to<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >; mapped_type = long long int; key_type = long long int]'
  991 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/unordered_map.h:991:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::unordered_map<long long int, long long int>::key_type&&' {aka 'long long int&&'}
  991 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:108:51: error: no match for 'operator+' (operand types are 'double' and 'vl' {aka 'std::vector<long long int>'})
  108 |     return dp[{ind, x}]=min(v+solve( (ind+1)*1e15 + y), solve( (ind+1)*1e15 + x));
      |                                      ~~~~~~~~~~~~ ^ ~
      |                                             |       |
      |                                             double  vl {aka std::vector<long long int>}
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
  627 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note:   template argument deduction/substitution failed:
a.cc:108:53: note:   'vl' {aka 'std::vector<long long int>'} is not derived from 'const std::reverse_iterator<_Iterator>'
  108 |     return dp[{ind, x}]=min(v+solve( (ind+1)*1e15 + y), solve( (ind+1)*1e15 + x));
      |                                                     ^
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
 1798 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note:   template argument deduction/substitution failed:
a.cc:108:53: note:   'vl' {aka 'std::vector<long long int>'} is not derived from 'const std::move_iterator<_IteratorL>'
  108 |     return dp[{ind, x}]=min(v+solve( (ind+1)*1e15 + y), solve( (ind+1)*1e15 + x));
      |                                                     ^
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/inclu