Language: C++

#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


void Dijkstra(Graph& G, ll s, Array& d,Array &u,ll l) {//O(|E|log|V|)
	d.resize(G.size());
	u.resize(G.size());
	REP(i, d.size())d[i] = l;
	REP(i, u.size())u[i] = INF;
	d[s] = 0;
	u[s] = 0;
	priority_queue<pair<pair<ll,ll>,ll>,vector<pair<pair<ll,ll>>>,greater<pair<pair<ll,ll>>>> q;

	q.push(make_pair(make_pair(0,0), s));
	while (!q.empty()) {
		ll k = q.top().first.first;
		ll dd = q.top().first.second;
		ll v = q.top().second;
		//cout << k << dd << v<<endl;
		q.pop();
		if (u[v] < k)continue;
      if(d[v]>dd)continue;

		REP(i, G[v].size()) {
			Edge e = G[v][i];
			ll nd = dd + e.cap;
			ll nk = k;
			if (nd > l ) {
				nd = e.cap;
				nk++;
			}
			if (u[e.to] > nk) {
				u[e.to] = nk;
				d[e.to] = nd;
				q.push(make_pair(make_pair(nk,nd), e.to));
				//cout << "aa" << nk << nd << e.to<<endl;
			}
			else if (u[e.to] == nk && d[e.to] > nd) {
				d[e.to] = nd;
				q.push(make_pair(make_pair(nk, nd), e.to));
				//cout << "bb" << nk << nd << e.to << endl;
			}
		}
	}
}

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

	ll n,m,l;
	cin >> n >> m >> l;
	Graph g(n);
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b>>c;
		a--; b--;
		add_edge(g, a, b, c, true, c);
	}

	Matrix ans(n);
	Matrix d(n);

	REP(i, n) {
		Dijkstra(g, i, d[i], ans[i], l);
	}
	/*
	for (auto i : ans) {
		for (auto j : i) {
			cout << j << " ";
		}
		cout << endl;
	}
	*/
	
	ll q;
	cin >> q;

	REP(i, q) {
		ll s, t;
		cin >> s >> t;
		s--; t--;
		if (ans[s][t] != INF) {
			cout << ans[s][t] << endl;
		}
		else {
			cout << -1 << endl;
		}
	}




	return 0;
}


Compiler output:
a.cc: In function 'void Dijkstra(Graph&, long long int, Array&, Array&, long long int)':
a.cc:68:67: error: wrong number of template arguments (1, should be 2)
   68 |         priority_queue<pair<pair<ll,ll>,ll>,vector<pair<pair<ll,ll>>>,greater<pair<pair<ll,ll>>>> q;
      |                                                                   ^~
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:3013:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
 3013 |     struct pair;
      |            ^~~~
a.cc:68:69: error: template argument 1 is invalid
   68 |         priority_queue<pair<pair<ll,ll>,ll>,vector<pair<pair<ll,ll>>>,greater<pair<pair<ll,ll>>>> q;
      |                                                                     ^
a.cc:68:69: error: template argument 2 is invalid
a.cc:68:94: error: wrong number of template arguments (1, should be 2)
   68 |         priority_queue<pair<pair<ll,ll>,ll>,vector<pair<pair<ll,ll>>>,greater<pair<pair<ll,ll>>>> q;
      |                                                                                              ^~
/usr/include/c++/14/bits/stl_iterator.h:3013:12: note: provided for 'template<class _T1, class _T2> struct std::pair'
 3013 |     struct pair;
      |            ^~~~
a.cc:68:79: error: template argument 1 is invalid
   68 |         priority_queue<pair<pair<ll,ll>,ll>,vector<pair<pair<ll,ll>>>,greater<pair<pair<ll,ll>>>> q;
      |                                                                               ^~~~~~~~~~~~~~~~~
a.cc:68:96: error: template argument 2 is invalid
   68 |         priority_queue<pair<pair<ll,ll>,ll>,vector<pair<pair<ll,ll>>>,greater<pair<pair<ll,ll>>>> q;
      |                                                                                                ^~
a.cc:68:96: error: template argument 3 is invalid
a.cc:70:11: error: request for member 'push' in 'q', which is of non-class type 'int'
   70 |         q.push(make_pair(make_pair(0,0), s));
      |           ^~~~
a.cc:71:19: error: request for member 'empty' in 'q', which is of non-class type 'int'
   71 |         while (!q.empty()) {
      |                   ^~~~~
a.cc:72:26: error: request for member 'top' in 'q', which is of non-class type 'int'
   72 |                 ll k = q.top().first.first;
      |                          ^~~
a.cc:73:27: error: request for member 'top' in 'q', which is of non-class type 'int'
   73 |                 ll dd = q.top().first.second;
      |                           ^~~
a.cc:74:26: error: request for member 'top' in 'q', which is of non-class type 'int'
   74 |                 ll v = q.top().second;
      |                          ^~~
a.cc:76:19: error: request for member 'pop' in 'q', which is of non-class type 'int'
   76 |                 q.pop();
      |                   ^~~
a.cc:91:35: error: request for member 'push' in 'q', which is of non-class type 'int'
   91 |                                 q.push(make_pair(make_pair(nk,nd), e.to));
      |                                   ^~~~
a.cc:96:35: error: request for member 'push' in 'q', which is of non-class type 'int'
   96 |                                 q.push(make_pair(make_pair(nk, nd), e.to));
      |                                   ^~~~