Language: C++

#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

typedef tuple<ll, ll> mtupl;

bool mycomp(mtupl x, mtupl y) {
	return get<1>(x) < get<1>(y);
}

vector<vector<ll>> memo;

ll get(int x, int y) {
	if (memo[x][y] != -1)
		return memo[x][y];

	if (x == 0) return 1;
	if (y < x) return 0;

	memo[x][y] = get(x, y - 1) + get(x - 1, y - 1);
	return memo[x][y];
}

ll mpow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; i < b; i++) {
		ans *= a;
		ans %= 1000000007;
	}
	return ans;
}

ll nCr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}
	for (int i = 1; i <= r; i++) {
		res /= i;
	}
	return res;
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int vmin(vector<int> v) {
	int min = INT32_MAX;
	for (auto it = v.begin(); it != v.end(); it++)
		min = std::min(min, *it);
	return min;
}
int vmax(vector<int> v) {
	int max = INT32_MIN;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	if (A == 0 || B == 0) return max(A, B);
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}
	return B;
}

ll _gcd(ll A, ll B) {
	return (B == 0) ? A : gcd(A % B, B);
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}

template<int index>
bool comp(tuple<ll, ll, ll, ll> a, tuple<ll, ll, ll, ll> b) {
	return get<index>(a) < get<index>(b);
}

int vector_finder(std::vector<ll> vec, ll number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return index;
	}
	else { // 発見できなかったとき
		return 0;
	}
}


int len(int x) {
	return (int)log10(x) + 1;
}

int same_vec(vector<int> a, vector<int> b) {
	int res = 1, num = a.size();
	for (int i = 0; i < num; i++) {
		if (a[i] != b[i]) {
			res = 0;
			break;
		}
	}
	return res;
}


ll fibs[100] = { 0 };
ll fib(int n) {
	if (fibs[n] == 0) {
		return fibs[n] = fib(n - 1) + fib(n - 2);
	}
	return fibs[n];
}



int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	ll N, M;
	cin >> N >> M;

	vector<pair<ll, ll>> vp(N,{-1,1000000}); //index,value
	vector<ll> values(M);
	rep(i, M) {
		ll a, b;
		cin >> a >> b;
		values[i] = a;
		rep(j, b) {
			ll tmp;
			cin >> tmp;
			tmp--;
			if (a < vp[tmp].second) {
				vp[tmp].first = i;
				vp[tmp].second = a;
			}
		}
	}

	set<ll> s;
	ll ans = 0;
	rep(i, N) {
		if (vp[i].first == -1) {
			cout << -1 << endl;
			goto ProgramEndPointLabel;
		}
		s.insert(vp[i].first);
	}

	for (auto it = s.begin(); it != s.end(); it++) {
		ans += values[*it];
	}

	cout << ans << endl;


ProgramEndPointLabel:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG


	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

typedef tuple<ll, ll> mtupl;

bool mycomp(mtupl x, mtupl y) {
	return get<1>(x) < get<1>(y);
}

vector<vector<ll>> memo;

ll get(int x, int y) {
	if (memo[x][y] != -1)
		return memo[x][y];

	if (x == 0) return 1;
	if (y < x) return 0;

	memo[x][y] = get(x, y - 1) + get(x - 1, y - 1);
	return memo[x][y];
}

ll mpow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; i < b; i++) {
		ans *= a;
		ans %= 1000000007;
	}
	return ans;
}

ll nCr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}
	for (int i = 1; i <= r; i++) {
		res /= i;
	}
	return res;
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int vmin(vector<int> v) {
	int min = INT32_MAX;
	for (auto it = v.begin(); it != v.end(); it++)
		min = std::min(min, *it);
	return min;
}
int vmax(vector<int> v) {
	int max = INT32_MIN;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	if (A == 0 || B == 0) return max(A, B);
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}
	return B;
}

ll _gcd(ll A, ll B) {
	return (B == 0) ? A : gcd(A % B, B);
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}

template<int index>
bool comp(tuple<ll, ll, ll, ll> a, tuple<ll, ll, ll, ll> b) {
	return get<index>(a) < get<index>(b);
}

int vector_finder(std::vector<ll> vec, ll number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return index;
	}
	else { // 発見できなかったとき
		return 0;
	}
}


int len(int x) {
	return (int)log10(x) + 1;
}

int same_vec(vector<int> a, vector<int> b) {
	int res = 1, num = a.size();
	for (int i = 0; i < num; i++) {
		if (a[i] != b[i]) {
			res = 0;
			break;
		}
	}
	return res;
}


ll fibs[100] = { 0 };
ll fib(int n) {
	if (fibs[n] == 0) {
		return fibs[n] = fib(n - 1) + fib(n - 2);
	}
	return fibs[n];
}



int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	ll N, M;
	cin >> N >> M;

	vector<pair<ll, ll>> vp(N,{-1,1000000}); //index,value
	vector<ll> values(M);
	rep(i, M) {
		ll a, b;
		cin >> a >> b;
		values[i] = a;
		rep(j, b) {
			ll tmp;
			cin >> tmp;
			tmp--;
			if (a < vp[tmp].second) {
				vp[tmp].first = i;
				vp[tmp].second = a;
			}
		}
	}

	set<ll> s;
	ll ans = 0;
	rep(i, N) {
		if (vp[i].first == -1) {
			cout << -1 << endl;
			goto ProgramEndPointLabel;
		}
		s.insert(vp[i].first);
	}

	for (auto it = s.begin(); it != s.end(); it++) {
		ans += values[*it];
	}

	cout << ans << endl;


ProgramEndPointLabel:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG


	return 0;
}




Compiler output:
a.cc: In function 'int vmin(std::vector<int>)':
a.cc:76:19: error: 'INT32_MAX' was not declared in this scope
   76 |         int min = INT32_MAX;
      |                   ^~~~~~~~~
a.cc:15:1: note: 'INT32_MAX' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
   14 | #include<stack>
  +++ |+#include <cstdint>
   15 | #define rep(i,n) for(ll i = 0; i < (ll)n; i++)
a.cc: In function 'int vmax(std::vector<int>)':
a.cc:82:19: error: 'INT32_MIN' was not declared in this scope; did you mean 'INT_MIN'?
   82 |         int max = INT32_MIN;
      |                   ^~~~~~~~~
      |                   INT_MIN
a.cc: At global scope:
a.cc:236:10: error: redefinition of 'const ll INF'
  236 | const ll INF = 1LL << 60;
      |          ^~~
a.cc:28:10: note: 'const ll INF' previously defined here
   28 | const ll INF = 1LL << 60;
      |          ^~~
a.cc:240:6: error: redefinition of 'bool mycomp(mtupl, mtupl)'
  240 | bool mycomp(mtupl x, mtupl y) {
      |      ^~~~~~
a.cc:32:6: note: 'bool mycomp(mtupl, mtupl)' previously defined here
   32 | bool mycomp(mtupl x, mtupl y) {
      |      ^~~~~~
a.cc:244:20: error: redefinition of 'std::vector<std::vector<long long int> > memo'
  244 | vector<vector<ll>> memo;
      |                    ^~~~
a.cc:36:20: note: 'std::vector<std::vector<long long int> > memo' previously declared here
   36 | vector<vector<ll>> memo;
      |                    ^~~~
a.cc:246:4: error: redefinition of 'll get(int, int)'
  246 | ll get(int x, int y) {
      |    ^~~
a.cc:38:4: note: 'll get(int, int)' previously defined here
   38 | ll get(int x, int y) {
      |    ^~~
a.cc:257:4: error: redefinition of 'll mpow(ll, ll)'
  257 | ll mpow(ll a, ll b) {
      |    ^~~~
a.cc:49:4: note: 'll mpow(ll, ll)' previously defined here
   49 | ll mpow(ll a, ll b) {
      |    ^~~~
a.cc:266:4: error: redefinition of 'll nCr(ll, ll)'
  266 | ll nCr(ll n, ll r) {
      |    ^~~
a.cc:58:4: note: 'll nCr(ll, ll)' previously defined here
   58 | ll nCr(ll n, ll r) {
      |    ^~~
a.cc:277:5: error: redefinition of 'int vsum(std::vector<int>)'
  277 | int vsum(vector<int> v) {
      |     ^~~~
a.cc:69:5: note: 'int vsum(std::vector<int>)' previously defined here
   69 | int vsum(vector<int> v) {
      |     ^~~~
a.cc:283:5: error: redefinition of 'int vmin(std::vector<int>)'
  283 | int vmin(vector<int> v) {
      |     ^~~~
a.cc:75:5: note: 'int vmin(std::vector<int>)' previously defined here
   75 | int vmin(vector<int> v) {
      |     ^~~~
a.cc: In function 'int vmin(std::vector<int>)':
a.cc:284:19: error: 'INT32_MAX' was not declared in this scope
  284 |         int min = INT32_MAX;
      |                   ^~~~~~~~~
a.cc:284:19: note: 'INT32_MAX' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc: At global scope:
a.cc:289:5: error: redefinition of 'int vmax(std::vector<int>)'
  289 | int vmax(vector<int> v) {
      |     ^~~~
a.cc:81:5: note: 'int vmax(std::vector<int>)' previously defined here
   81 | int vmax(vector<int> v) {
      |     ^~~~
a.cc: In function 'int vmax(std::vector<int>)':
a.cc:290:19: error: 'INT32_MIN' was not declared in this scope; did you mean 'INT_MIN'?
  290 |         int max = INT32_MIN;
      |                   ^~~~~~~~~
      |                   INT_MIN
a.cc: At global scope:
a.cc:296:4: error: redefinition of 'll gcd(ll, ll)'
  296 | ll gcd(ll A, ll B) {
      |    ^~~
a.cc:88:4: note: 'll gcd(ll, ll)' previously defined here
   88 | ll gcd(ll A, ll B) {
      |    ^~~
a.cc:307:4: error: redefinition of 'll _gcd(ll, ll)'
  307 | ll _gcd(ll A, ll B) {
      |    ^~~~
a.cc:99:4: note: 'll _gcd(ll, ll)' previously defined here
   99 | ll _gcd(ll A, ll B) {
      |    ^~~~
a.cc:311:14: error: redefinition of 'std::vector<bool> to_binary(int)'
  311 | vector<bool> to_binary(int x) {
      |              ^~~~~~~~~
a.cc:103:14: note: 'std::vector<bool> to_binary(int)' previously defined here
  103 | vector<bool> to_binary(int x) {
      |              ^~~~~~~~~
a.cc:321:6: error: redefinition of 'template<int index> bool comp(std::tuple<long long int, long long int, long long int, long long int>, std::tuple<long long int, long long int, long long int, long long int>)'
  321 | bool comp(tuple<ll, ll, ll, ll> a, tuple<ll, ll, ll, ll> b) {
      |      ^~~~
a.cc:113:6: note: 'template<int index> bool comp(std::tuple<long long int, long long int, long long int, long long int>, std::tuple<long long int, long long int, long long int, long long int>)' previously declared here
  113 | bool comp(tuple<ll, ll, ll, ll> a, tuple<ll, ll, ll, ll> b) {
      |      ^~~~
a.cc:325:5: error: redefinition of 'int vector_finder(std::vector<long long int>, ll)'
  325 | int vector_finder(std::vector<ll> vec, ll number) {
      |     ^~~~~~~~~~~~~
a.cc:117:5: note: 'int vector_finder(std::vector<long long int>, ll)' previously defined here
  117 | int vector_finder(std::vector<ll> vec, ll number) {
      |     ^~~~~~~~~~~~~
a.cc:337:5: error: redefinition of 'int len(int)'
  337 | int len(int x) {
      |     ^~~
a.cc:129:5: note: 'int len(int)' previously defined here
  129 | int len(int x) {
      |     ^~~
a.cc:341:5: error: redefinition of 'int same_vec(std::vector<int>, std::vector<int>)'
  341 | int same_vec(vector<int> a, vector<int> b) {
      |     ^~~~~~~~
a.cc:133:5: note: 'int same_vec(std::vector<int>, std::vector<int>)' previously defined here
  133 | int same_vec(vector<int> a, vector<int> b) {
      |     ^~~~~~~~
a.cc:353:4: error: redefinition of 'll fibs [100]'
  353 | ll fibs[100] = { 0 };
      |    ^~~~
a.cc:145:4: note: 'll fibs [100]' previously defined here
  145 | ll fibs[100] = { 0 };
      |    ^~~~
a.cc:354:4: error: redefinition of 'll fib(int)'
  354 | ll fib(int n) {
      |    ^~~
a.cc:146:4: note: 'll fib(int)' previously defined here
  146 | ll fib(int n) {
      |    ^~~
a.cc:363:5: error: redefinition of 'int main()'
  363 | int main(void) {
      |     ^~~~
a.cc:155:5: note: 'int main()' previously defined here
  155 | int main(void) {
      |     ^~~~