Language: C++

#include <bits/stdc++.h>
#define FOR(i,a,b) for(register int i=(a);i<(b);++i)
#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
#define pi pair<int,int>
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 305;
const int maxm = 200005;
const int inf = 2147483647;
typedef long long ll;
const double eps = 1e-9;
const long long INF = 9223372036854775807ll;
ll qpow(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c;b>>=1;}return ans;}
int n,m,l,h[maxn];
int path[maxn][maxn];
ll d[maxn][maxn];
int slove(int s,int t){
	int ans=0;
	if(d[s][t]==INF/4ll)ans=-1;
	else{
		vector<int>ps;
		int u=t;
		while(u!=s){
			int k=path[s][u];
			ps.push_back(d[k][u]);
			u=k;
		}
		int cur=l;
		ROF(i,ps.size()-1,0){
//			printf("%d\n",ps[i]);
			if(ps[i]<=cur)cur-=ps[i];
			else cur=l-ps[i],ans++;
		}
	}
	return ans;
}
void floyd(){
	FOR(k,1,n+1)
	FOR(i,1,n+1)
	FOR(j,1,n+1){
		if(d[i][j]>d[i][k]+d[k][j]){
			d[i][j]=d[i][k]+d[k][j];
			path[i][j]=path[k][j];
		}
	}
}
int main(){
	scanf("%d%d%d",&n,&m,&l);
	FOR(i,1,n+1)
	FOR(j,1,n+1)if(i!=j)d[i][j]=INF/4,path[i][j]=i;
	while(m--){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if(c>l)continue;
		d[a][b]=d[b][a]=min(d[a][b],c);
	}
	floyd();
	int q;
	scanf("%d",&q);
	while(q--){
		int s,t;
		scanf("%d%d",&s,&t);
		printf("%d\n",slove(s,t));
	}
}
/*
2 1 4
1 2 5
100
*/

Compiler output:
a.cc: In function 'int slove(int, int)':
a.cc:33:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   33 |                 ROF(i,ps.size()-1,0){
      |                     ^
a.cc:3:37: note: in definition of macro 'ROF'
    3 | #define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
      |                                     ^
a.cc: In function 'void floyd()':
a.cc:42:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   42 |         FOR(k,1,n+1)
      |             ^
a.cc:2:37: note: in definition of macro 'FOR'
    2 | #define FOR(i,a,b) for(register int i=(a);i<(b);++i)
      |                                     ^
a.cc:43:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   43 |         FOR(i,1,n+1)
      |             ^
a.cc:2:37: note: in definition of macro 'FOR'
    2 | #define FOR(i,a,b) for(register int i=(a);i<(b);++i)
      |                                     ^
a.cc:44:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   44 |         FOR(j,1,n+1){
      |             ^
a.cc:2:37: note: in definition of macro 'FOR'
    2 | #define FOR(i,a,b) for(register int i=(a);i<(b);++i)
      |                                     ^
a.cc: In function 'int main()':
a.cc:53:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   53 |         FOR(i,1,n+1)
      |             ^
a.cc:2:37: note: in definition of macro 'FOR'
    2 | #define FOR(i,a,b) for(register int i=(a);i<(b);++i)
      |                                     ^
a.cc:54:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   54 |         FOR(j,1,n+1)if(i!=j)d[i][j]=INF/4,path[i][j]=i;
      |             ^
a.cc:2:37: note: in definition of macro 'FOR'
    2 | #define FOR(i,a,b) for(register int i=(a);i<(b);++i)
      |                                     ^
a.cc:59:36: error: no matching function for call to 'min(ll&, int&)'
   59 |                 d[a][b]=d[b][a]=min(d[a][b],c);
      |                                 ~~~^~~~~~~~~~~
In file included 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_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:59:36: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   59 |                 d[a][b]=d[b][a]=min(d[a][b],c);
      |                                 ~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:59:36: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   59 |                 d[a][b]=d[b][a]=min(d[a][b],c);
      |                                 ~~~^~~~~~~~~~~