Language: C++

#include <bits/stdc++.h>

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)
#define SORT(a) sort(ALL(a))
#define VSORT(a, type) sort(ALL(a),greater<type>())
#define MAPIN(a,i,j) (a).insert(make_pair(i,j))

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

#define INF pow(10,9)+1

using namespace std;

typedef unsigned long long lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > Matrix;

vector< vll >d;
vector< vll >next;
ll  V;

void wf(){
    ll i,j,k;
    rep(k,V){
        rep(i,V){
            rep(j,V){
                if(d[i][j]>d[i][k]+d[k][j]){
                    next[i][j]=next[i][k];
                    d[i][j]=d[i][k]+d[k][j];
                }
            }
        }
    }
}
vll get_path(ll s,ll t){
    int cur;
    vll path;
    for(cur=s;cur!=t;cur=next[cur][t])PB(path,cur);
    return path;
}

int main() {
    ll n,m,l,i,j,k,a,b,c,q;

    cin>>n>>m>>l;
    V=n;
    SIZE(d,n);
    SIZE(next,n);
    rep(i,n){
        SIZE(d[i],n);
        SIZE(next[i],n);
        rep(j,n){
            d[i][j]=INF;
            next[i][j]=j;
        }
    }
    rep(i,m){
        cin>>a>>b>>c;
        a--;
        b--;
        if(c<=l){
            d[a][b]=c;
            d[b][a]=c;
        }
    }
    wf();
    cin>>q;
    rep(i,q){
        cin>>a>>b;
        a--;
        b--;
        if(d[a][b]==INF){
            cout<<-1<<endl;
        }
        else{
            vll p=get_path(a,b);
            k=l;
            m=0;
            rep(j,p.size()-1){
                k-=d[p[j]][p[j+1]];
                if(k<0){
                    m++;
                    k=l-d[p[j]][p[j+1]];
                }
            }
            k-=d[p[j]][b];
            if(k<0)m++;
            cout<<m<<endl;
        }
    }
	
	return 0;
}


Compiler output:
a.cc: In function 'void wf()':
a.cc:40:21: error: reference to 'next' is ambiguous
   40 |                     next[i][j]=next[i][k];
      |                     ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:31:14: note:                 'std::vector<std::vector<long long int> > next'
   31 | vector< vll >next;
      |              ^~~~
a.cc:40:32: error: reference to 'next' is ambiguous
   40 |                     next[i][j]=next[i][k];
      |                                ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:31:14: note:                 'std::vector<std::vector<long long int> > next'
   31 | vector< vll >next;
      |              ^~~~
a.cc: In function 'vll get_path(ll, ll)':
a.cc:50:26: error: reference to 'next' is ambiguous
   50 |     for(cur=s;cur!=t;cur=next[cur][t])PB(path,cur);
      |                          ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:31:14: note:                 'std::vector<std::vector<long long int> > next'
   31 | vector< vll >next;
      |              ^~~~
a.cc: In function 'int main()':
a.cc:60:10: error: reference to 'next' is ambiguous
   60 |     SIZE(next,n);
      |          ^~~~
a.cc:9:20: note: in definition of macro 'SIZE'
    9 | #define SIZE(a,n) (a).resize(n)
      |                    ^
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:31:14: note:                 'std::vector<std::vector<long long int> > next'
   31 | vector< vll >next;
      |              ^~~~
a.cc:63:14: error: reference to 'next' is ambiguous
   63 |         SIZE(next[i],n);
      |              ^~~~
a.cc:9:20: note: in definition of macro 'SIZE'
    9 | #define SIZE(a,n) (a).resize(n)
      |                    ^
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:31:14: note:                 'std::vector<std::vector<long long int> > next'
   31 | vector< vll >next;
      |              ^~~~
a.cc:66:13: error: reference to 'next' is ambiguous
   66 |             next[i][j]=j;
      |             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:31:14: note:                 'std::vector<std::vector<long long int> > next'
   31 | vector< vll >next;
      |              ^~~~