Language: C++

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef tuple<int,int,int,int> Tiiii;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}



// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed 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]);
    // }

    int n,m,l,q;
    cin>>n>>m>>l;
    Vi a(m),b(m),c(m);
    vector<vector<Pii>> connect(n);
    REP(i,0,m){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        if(c[i]<=l){
        connect[a[i]].pb(mp(b[i],c[i]));
        connect[b[i]].pb(mp(a[i],c[i]));
        }
    }

    cin>>q;
    Vi s(q),t(q);
    vin(s,t);
    REP(i,0,q){s[i]--;t[i]--;}

    VVi ans(n,Vi(n,INF));

REP(i,0,q){
    if(ans[s[i]][t[i]!=INF){
        cout<<ans[s[i]][t[i]<<endl;
        continue;
    }

    VPii dist(n,mp(INF,INF));

    priority_queue<Tiiii,vector<Tiiii>,greater<Tiiii>> q;
    q.push(make_tuple(0,0,s[i],-1));
    while(!q.empty()){
        int nowdist1,nowdist2,now,past;
        tie(nowdist1,nowdist2,now,past)=q.top();
        q.pop();
//        cout<<"now="<<now<<"nowdist="<<nowdist1<<" "<<nowdist2<<endl;
        if(nowdist1>dist[now].first) continue;
        else if(nowdist1==dist[now].first && nowdist2>dist[now].second) continue;
        dist[now]=mp(nowdist1,nowdist2);
        if(now==t[i]) break;
        REP(i,0,connect[now].size()){
            int next=connect[now][i].first,cost=connect[now][i].second;
            int nextdist1=nowdist1,nextdist2=nowdist2+cost;
            if(nextdist2>l){
                nextdist1++;
                nextdist2 = cost;
            }
            if(next!=past && (nextdist1<dist[next].first || (nextdist1==dist[next].first && nextdist2<dist[next].second)) && cost<=l){
                q.push(make_tuple(nextdist1,nextdist2,next,now));
//                cout<<"push:"<<next<<" nextdist="<<nextdist1<<" "<<nextdist2<<endl;
                dist[next]=mp(nextdist1,nextdist2);
            }
        }
    }
    if(dist[t[i]].first!=INF){
        cout<<dist[t[i]].first<<endl;
        ans[s[i]][t[i]]=dist[t[i]].first;
        ans[t[i]][s[i]]=dist[t[i]].first;
    }
    else{
        cout<<-1<<endl;
        ans[s[i]][t[i]]=-1;
        ans[t[i]][s[i]]=-1;
    }
}


    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:90:27: error: expected ']' before ')' token
   90 |     if(ans[s[i]][t[i]!=INF){
      |                           ^
a.cc:91:29: error: invalid operands of types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and 'const char [2]' to binary 'operator<<'
   91 |         cout<<ans[s[i]][t[i]<<endl;
a.cc:91:35: error: expected ']' before ';' token
   91 |         cout<<ans[s[i]][t[i]<<endl;
      |                                   ^