Language: C++

#include <vector>
#include <algorithm>
#include <deque>
#include <numeric>
#include <utility>
#define sign(a) ((a>0)-(a<0))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define LL long long
#define INF (LL)(1LL<<60)
#define all(a) a.begin(), a.end()
#define gr greater<LL>()

using namespace std;
typedef pair<pair<LL, LL>, double> P;

void solve(long long N, long long M, long long L, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C, long long Q, std::vector<long long> s, std::vector<long long> t){
    vector<vector<LL>> edges(N, vector<LL>(N, INF));

    rep(i, M){
        if(C[i]>L)continue;
        edges[A[i]-1][B[i]-1] = C[i];
        edges[B[i]-1][A[i]-1] = C[i];
    }

    vector<vector<pair<LL, LL>>> shortests;

    rep(S, N){
        vector<pair<LL, LL>> shortest(N, make_pair(INF,INF));

        priority_queue<P, std::vector<P>, std::greater<P>> q;
        q.push(make_pair(make_pair(0, -L), S));

        while(!q.empty()){
            LL src = q.top().second;
            auto l0 = q.top().first;
            q.pop();
            if(l0 >= shortest[src])continue;
            shortest[src] = l0;
            for(LL dst=0ll; dst<N; dst++){
                auto l = edges[src][dst];
                if(l>=INF)continue;
                auto rem = -l0.second;
                auto cnt = l0.first + (l > rem ? 1 : 0);
                auto newrem = (-1)*(l > rem ? L-l : rem-l);
                auto l1 = make_pair(cnt, newrem);
                if(l1 < shortest[dst]){
                    q.push(make_pair(l1, dst));
                }
            }
        }
        shortests.emplace_back(shortest);
    }

    rep(i,Q){
        LL S = s[i]-1;
        LL G = t[i]-1;
        auto ans = shortests[S][G];
        cout <<  (ans.first < INF ? ans.first : -1) << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long L;
    scanf("%lld",&L);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    std::vector<long long> C(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> s(Q);
    std::vector<long long> t(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&s[i]);
        scanf("%lld",&t[i]);
    }
    solve(N, M, L, std::move(A), std::move(B), std::move(C), Q, std::move(s), std::move(t));
    return 0;
}


Compiler output:
a.cc: In function 'void solve(long long int, long long int, long long int, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>, long long int, std::vector<long long int>, std::vector<long long int>)':
a.cc:30:9: error: 'priority_queue' was not declared in this scope
   30 |         priority_queue<P, std::vector<P>, std::greater<P>> q;
      |         ^~~~~~~~~~~~~~
a.cc:6:1: note: 'std::priority_queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
    5 | #include <utility>
  +++ |+#include <queue>
    6 | #define sign(a) ((a>0)-(a<0))
a.cc:30:25: error: expected primary-expression before ',' token
   30 |         priority_queue<P, std::vector<P>, std::greater<P>> q;
      |                         ^
a.cc:30:41: error: expected primary-expression before ',' token
   30 |         priority_queue<P, std::vector<P>, std::greater<P>> q;
      |                                         ^
a.cc:30:57: error: expected primary-expression before '>' token
   30 |         priority_queue<P, std::vector<P>, std::greater<P>> q;
      |                                                         ^~
a.cc:30:60: error: 'q' was not declared in this scope
   30 |         priority_queue<P, std::vector<P>, std::greater<P>> q;
      |                                                            ^
a.cc:58:9: error: 'cout' was not declared in this scope
   58 |         cout <<  (ans.first < INF ? ans.first : -1) << endl;
      |         ^~~~
a.cc:6:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    5 | #include <utility>
  +++ |+#include <iostream>
    6 | #define sign(a) ((a>0)-(a<0))
a.cc:58:56: error: 'endl' was not declared in this scope
   58 |         cout <<  (ans.first < INF ? ans.first : -1) << endl;
      |                                                        ^~~~
a.cc:6:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    5 | #include <utility>
  +++ |+#include <ostream>
    6 | #define sign(a) ((a>0)-(a<0))
a.cc: In function 'int main()':
a.cc:64:5: error: 'scanf' was not declared in this scope
   64 |     scanf("%lld",&N);
      |     ^~~~~