Language: C++

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e12;

void warshall_floyd(vector<vector<long long>> &_Date){
    for(int k = 0; k < _Date.size(); k++){        //経由頂点
        for(int i = 0; i < _Date.size(); i++){    //始点
            for(int j = 0; j < _Date.size(); j++){//終点
                _Date[i][j] = min(_Date[i][j], _Date[i][k] + _Date[k][j]);
            }
        }
    }
}

struct UnionFind {
    vector<int> data;
    int sz;
    UnionFind(int _sz) : data(_sz, -1), sz(_sz) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x; sz--;
        return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return sz; }
};


int main(){
    int N, M;
    long long L;
    cin >> N >> M >> L;
    UnionFind uf(N);
    vector<vector<int>> G(N, vector<int>());
    vector<vector<long long>> dist(N, vector<long long>(N, INF));
    for(int i = 0; i < M; i++){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--;
        b--;
        uf.unionSet(a, b);
        G[a].push_back(b);
        G[b].push_back(a);
        dist[a][b] = c;
        dist[b][a] = c;
    }
    
    warshall_floyd(dist);
    
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int s, g;
        cin >> s >> g;
        s--;
        g--;
        long long ans = -1;
        if(uf.findSet(s, g)){
            vector<bool> seen(N, false);
            stack<pair<int, pair<long long, long long>>> sta;
            sta.push(make_pair(s, make_pair(0, L)));
            
            while(!sta.empty()){
                pair<int, pair<long long, long long>>> p = sta.top();
                sta.pop();
                int now = p.first;
                long long cnt = p.second.first;
                long long tank = p.second.second;
                seen[now] = true;
                if(now == g){
                    ans = cnt;
                    break;
                }
                for(auto v : G[now]){
                    if(seen[v])continue;
                    long long next = tank - dist[now][v];
                    if(mext < 0){
                        sta.push(make_pair(v, make_pair(cnt + 1, L)));
                    }else{
                        sta.push(make_pair(v, make_pair(cnt, next)));
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:68:54: error: expected unqualified-id before '>' token
   68 |                 pair<int, pair<long long, long long>>> p = sta.top();
      |                                                      ^
a.cc:70:27: error: 'p' was not declared in this scope
   70 |                 int now = p.first;
      |                           ^
a.cc:81:24: error: 'mext' was not declared in this scope; did you mean 'next'?
   81 |                     if(mext < 0){
      |                        ^~~~
      |                        next