Language: C++

#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#define REP(i, a, b) for(int i = (a); i < int(b); ++i)
#define rep(i, n) REP(i, 0, n)

template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

struct state {
	int v, t, d;
	state(int v_, int t_, int d_):v(v_), t(t_), d(d_) {}
	bool operator>(const state &s) const {
		return d > s.d;
	}
};

struct edge {
	int to, cost, time, company;
	edge(int to_, int cost_, int time_, int company_):to(to_), cost(cost_), time(time_), company(company_) {}
};

constexpr int MAX_K = 8;
constexpr int INF = (1 << 29);

int dijkstra(int s, int t, int h, const vector<vector<edge>> &G, const bitset<MAX_K> &b) {
	const int n = G.size();
	vector<vector<int>> dist(n, vector<int>(h + 1, INF));
	priority_queue<state, vector<state>, greater<state>> que;

	dist[s][0] = 0;
	que.push(state(s, 0, 0));

	while(!que.empty()) {
		const state s = que.top();
		que.pop();

		if(s.d > dist[s.v][s.t]) continue;
		if(s.v == t) return s.d;

		for(const auto &e : G[s.v]) {
			const int next_time = s.t + e.time;
			if(next_time > h) continue;

			const int next_dist = s.d + (b[e.company] ? 0 : e.cost);
			if(dist[e.to][next_time] > next_dist) {
				dist[e.to][next_time] = next_dist;
				que.emplace(e.to, next_time, next_dist);
			}
		}
	}

	return INF;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	for(int n, m, h, k; cin >> n >> m >> h >> k && n;) {
		vector<vector<edge>> G(n);

		rep(i, m) {
			int a, b, c, t, r;
			cin >> a >> b >> c >> t >> r;
			--a; --b; --r;
			G[a].emplace_back(b, c, t, r);
			G[b].emplace_back(a, c, t, r);
		}

		int s, t, p;
		cin >> s >> t >> p;
		--s; --t;

		vector<int> pass(p, 0);
		vector<int> value(p);

		rep(i, p) {
			int l;
			cin >> l >> value[i];

			rep(j, l) {
				int q;
				cin >> q;
				pass[i] |= (1 << (q - 1));
			}
		}

		vector<int> min_cost(1 << k, INF);
		min_cost[0] = 0;

		int ans = INF;
		rep(i, 1 << k) {
			if(min_cost[i] >= ans) continue;
			
			chmin(ans, dijkstra(s, t, h, G, bitset<MAX_K>(i)) + min_cost[i]);

			rep(j, p) {
				const int next = (i | pass[j]);
				chmin(min_cost[next], min_cost[i] + value[j]);
			}
		}

		cout << (ans == INF ? -1 : ans) << endl;
	}
	return EXIT_SUCCESS;
}

Compiler output:
a.cc:29:72: error: 'bitset' does not name a type
   29 | int dijkstra(int s, int t, int h, const vector<vector<edge>> &G, const bitset<MAX_K> &b) {
      |                                                                        ^~~~~~
a.cc:29:78: error: expected ',' or '...' before '<' token
   29 | int dijkstra(int s, int t, int h, const vector<vector<edge>> &G, const bitset<MAX_K> &b) {
      |                                                                              ^
a.cc: In function 'int dijkstra(int, int, int, const std::vector<std::vector<edge> >&, int)':
a.cc:48:54: error: 'b' was not declared in this scope
   48 |                         const int next_dist = s.d + (b[e.company] ? 0 : e.cost);
      |                                                      ^
a.cc: In function 'int main()':
a.cc:99:57: error: 'bitset' was not declared in this scope
   99 |                         chmin(ans, dijkstra(s, t, h, G, bitset<MAX_K>(i)) + min_cost[i]);
      |                                                         ^~~~~~
a.cc:5:1: note: 'std::bitset' is defined in header '<bitset>'; this is probably fixable by adding '#include <bitset>'
    4 | #include <queue>
  +++ |+#include <bitset>
    5 | #include <vector>