Language: C++

//#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib>      // srand,rand


using namespace std;
#define ll long long

#define modd 1000000007
#define INF 8223372036854775807ll


typedef pair<long long, long long> pl;



typedef string::const_iterator State;
class ParseError {};






/*

class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/

/*
struct SegmentTree {
private:
	ll n;
	vector<ll> node;

public:
	// 元配列 v をセグメント木で表現する
	SegmentTree(vector<ll> v) {
		// 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
		// セグメント木全体で必要なノード数は 2n-1 個である
		ll sz = v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(2 * n - 1, INF);

		// 最下段に値を入れたあとに、下の段から順番に値を入れる
		// 値を入れるには、自分の子の 2 値を参照すれば良い
		for (ll i = 0; i < sz; i++) node[i + n - 1] = v[i];
		for (ll i = n - 2; i >= 0; i--) node[i] = min(node[2 * i + 1], node[2 * i + 2]);
	}


	void update(ll x, ll val) {
		// 最下段のノードにアクセスする
		x += (n - 1);

		// 最下段のノードを更新したら、あとは親に上って更新していく
		node[x] = val;
		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = min(node[2 * x + 1], node[2 * x + 2]);
		}
	}

};
*/





ll N, M, K, a, b, c, d, e, H, W, L, T;
ll x, y;
ll A[2000004] = {};
ll B[2000004] = {};
ll C[2000004] = {};
ll D[1000006] = {};
ll E[1000006] = {};
bool f;
string S[200000];
string SS;
set <long long>sll;
pl bufpl;
vector <long long>vl[300005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;
queue<ll> ql;
multiset<pl> plmset;


struct ST
{
	ll first;
	ll second;
	ll kaisuu;
	ll nenryou;
	ll city;

	bool operator<(const ST& another) const
	{
		return kaisuu < another.kaisuu;//比較
	};

};
//queue<ST> qst;
priority_queue<ST, vector<ST>, greater<ST> > qst;
ST bufst;


/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/

/*
long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


*/


ll zettai(ll aa) {

	if (aa < 0) {
		aa *= -1;
	}
	return aa;

}



class UnionFind
{

public:


	vector <ll>pairent;
	vector <ll>depth;
	vector <ll>size;


	UnionFind(ll Amount) : pairent(Amount, 1), depth(Amount, 1), size(Amount, 1) {

		for (ll i = 0; i < Amount; i++) {
			pairent[i] = i;
		}


	}


	ll FindPairent(ll x) {
		if (pairent[x] == x)return x;
		else return pairent[x] = FindPairent(pairent[x]);

	}


	ll Merge(ll x, ll y) {
		x = FindPairent(x);
		y = FindPairent(y);

		if (x != y) {
			if (depth[x] > depth[y]) {
				pairent[y] = pairent[x];
				return size[x] += size[y];
			}
			else {
				pairent[x] = pairent[y];
				if (depth[x] == depth[y]) {
					depth[y] ++;
				}

				return size[y] += size[x];
			}

		}
		else {
			return -1;
		}



	}



	bool IsSame(ll x, ll y) {
		if (FindPairent(x) == FindPairent(y))return true;
		else return false;
	}


	ll GetSize(ll x) {
		x = FindPairent(x);
		return size[x];
	}


};

ll Q;
ll qq[2][1000006];

ll costs[301][301] = {};
ll ans[2][301][301] = {};

ST buffst;

bool ff[4001][4001] = {};

int main() {

	cin >> N>>M>>L;

	for (int i = 0; i < 301; i++) {
		for (int j = 0; j < 301; j++) {
			costs[i][j] = -1;
			ans[0][i][j] = INF;
			ans[1][i][j] = -1;
		}
	}
	
	for (int i = 0; i < M; i++) {
		cin >> A[i]>>B[i]>>C[i];
		if (L >= C[i]) {
			costs[A[i]][B[i]] = C[i];
			costs[B[i]][A[i]] = C[i];
		}
	}

	for (int i = 1; i <= N; i++) {
		bufst.city = i;
		bufst.kaisuu = 0;
		bufst.nenryou = L;
		ans[0][i][i] = 0;
		ans[1][i][i] = L;
		
		qst.push(bufst);

		while (!qst.empty()) {
			bufst = qst.front();
			

			if (bufst.kaisuu == ans[0][i][bufst.city] && bufst.nenryou == ans[1][i][bufst.city] && ff[i][bufst.city] == false) {
				ff[i][bufst.city] = true;
				for (int j = 1; j <= N; j++) {
					if (costs[bufst.city][j] >= 0) {
						buffst.city = j;
						if (bufst.nenryou >= costs[bufst.city][j]) {
							buffst.kaisuu = bufst.kaisuu;
							buffst.nenryou = bufst.nenryou - costs[bufst.city][j];
						}
						else {
							buffst.kaisuu = bufst.kaisuu + 1;
							buffst.nenryou = L - costs[bufst.city][j];
						}

						if (buffst.kaisuu < ans[0][i][j]) {
							ans[0][i][j] = buffst.kaisuu;
							ans[1][i][j] = buffst.nenryou;
							qst.push(buffst);
							ff[i][j] = false;
						}
						else if (buffst.kaisuu == ans[0][i][j] && buffst.nenryou > ans[1][i][j]) {
							ans[0][i][j] = buffst.kaisuu;
							ans[1][i][j] = buffst.nenryou;
							qst.push(buffst);
							ff[i][j] = false;
						}

					}



				}


				
			}

			qst.pop();
		}

	}

	cin >> Q;

	for (int i = 0; i < Q; i++) {
		cin >> qq[0][i] >> qq[1][i];
	}


	for (int i = 0; i < Q; i++) {
		if (ans[0][qq[0][i]][qq[1][i]] == INF) {
			cout << -1 << endl;
		}
		else {
			cout << ans[0][qq[0][i]][qq[1][i]] << endl;
		}
	}

	//cout << fixed << setprecision(10) << ansa << endl;
	return 0;




}


Compiler output:
a.cc: In function 'int main()':
a.cc:317:37: error: 'class std::priority_queue<ST, std::vector<ST>, std::greater<ST> >' has no member named 'front'
  317 |                         bufst = qst.front();
      |                                     ^~~~~
In file included from /usr/include/c++/14/string:49,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_function.h: In instantiation of 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = ST]':
/usr/include/c++/14/bits/predefined_ops.h:196:23:   required from 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<ST*, std::vector<ST> >; _Value = ST; _Compare = std::greater<ST>]'
  196 |         { return bool(_M_comp(*__it, __val)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:140:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ST*, vector<ST> >; _Distance = long int; _Tp = ST; _Compare = __gnu_cxx::__ops::_Iter_comp_val<greater<ST> >]'
  140 |       while (__holeIndex > __topIndex && __comp(__first + __parent, __value))
      |                                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:216:23:   required from 'void std::push_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<ST*, vector<ST> >; _Compare = greater<ST>]'
  216 |       std::__push_heap(__first, _DistanceType((__last - __first) - 1),
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  217 |                        _DistanceType(0), _GLIBCXX_MOVE(__value), __cmp);
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:739:16:   required from 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = ST; _Sequence = std::vector<ST>; _Compare = std::greater<ST>; value_type = ST]'
  739 |         std::push_heap(c.begin(), c.end(), comp);
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:314:11:   required from here
  314 |                 qst.push(bufst);
      |                 ~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_function.h:395:20: error: no match for 'operator>' (operand types are 'const ST' and 'const ST')
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:462:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  462 |     operator>(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:462:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const ST' is not derived from 'const std::reverse_iterator<_Iterator>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:507:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  507 |     operator>(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:507:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const ST' is not derived from 'const std::reverse_iterator<_Iterator>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1714:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1714 |     operator>(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1714:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const ST' is not derived from 'const std::move_iterator<_IteratorL>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1774:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1774 |     operator>(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1774:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const ST' is not derived from 'const std::move_iterator<_IteratorL>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~