Language: C++

#pragma GCC target("sse,sse2,sse3,sse4.1,sse4.2,popcnt,abm,mmx,avx")
#pragma comment(linker,"/STACK:102400000,102400000")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const ll inf=1e18,N=3001001,MAX=301;
inline void read(register ll &ret)
{
    ret=0;register ll pd=0;register char c=getchar();
    while(!isdigit(c)){pd|=c=='-';c=getchar();}
    while(isdigit(c)){ret=(ret<<1)+(ret<<3)+(c^48);c=getchar();}
    ret=pd?-ret:ret;
}
ll n,m,sum[MAX][MAX],dp[MAX][MAX],f[MAX][MAX],l,q;
int main()
{
	read(n);
	read(m);
	read(l);
	for(re int i=1;i<=n;i++)
		for(re int j=1;j<=n;j++)
			dp[i][j]=f[i][j]=inf;
	for(register ll i=1,a,b,c;i<=m;i++)
	{
		read(a);
		read(b);
		read(c);
		dp[a][b]=dp[b][a]=c;
	}
	for(register int i=1;i<=n;i++)
		for(register int j=1;j<=n;j++)
			for(register int k=1;k<=n;k++)
				if(dp[i][j]>dp[i][k]+dp[k][j])
					dp[i][j]=min(dp[i][k]+dp[k][j],dp[i][j]);
	memset(f,0x3f,sizeof(f));
	for(register int i=1;i<=n;i++)
		for(register int j=i+1;j<=n;j++)
			if(dp[i][j]<=l)
				f[i][j]=f[j][i]=1;
	for(register int i=1;i<=n;i++)
		for(register int j=1;j<=n;j++)
			for(register int k=1;k<=n;k++)
				if(f[i][j]>f[i][k]+f[k][j])
					f[i][j]=min(f[i][k]+f[k][j],f[i][j]);
	read(q);
	for(register ll i=1,a,b;i<=q;i++)
	{
		read(a);
		read(b);
		printf("%lld\n",f[a][b]==inf?-1ll:f[a][b]-1);
	}
	exit(0);
}


Compiler output:
a.cc:24:39: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
   24 | #pragma GCC optimize("-fwhole-program")
      |                                       ^
a.cc:31:41: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
   31 | #pragma GCC optimize("-fstrict-overflow")
      |                                         ^
a.cc:33:41: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
   33 | #pragma GCC optimize("-fcse-skip-blocks")
      |                                         ^
a.cc:46:51: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
   46 | #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                   ^
a.cc:54:31: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   54 | inline void read(register ll &ret)
      |                               ^~~
a.cc:54:34: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   54 | inline void read(register ll &ret)
      |                                  ^
a.cc:54:34: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
a.cc:54:34: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
a.cc:54:34: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
a.cc: In function 'void read(ll&)':
a.cc:56:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   56 |     ret=0;register ll pd=0;register char c=getchar();
      |                       ^~
a.cc:56:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   56 |     ret=0;register ll pd=0;register char c=getchar();
      |                                          ^
a.cc: At global scope:
a.cc:62:10: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   62 | int main()
      |          ^
a.cc:62:10: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
a.cc:62:10: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
a.cc:62:10: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
a.cc: In function 'int main()':
a.cc:67:13: error: 're' was not declared in this scope
   67 |         for(re int i=1;i<=n;i++)
      |             ^~
a.cc:67:24: error: 'i' was not declared in this scope
   67 |         for(re int i=1;i<=n;i++)
      |                        ^
a.cc:68:23: error: expected ';' before 'int'
   68 |                 for(re int j=1;j<=n;j++)
      |                       ^~~~
      |                       ;
a.cc:68:32: error: 'j' was not declared in this scope
   68 |                 for(re int j=1;j<=n;j++)
      |                                ^
a.cc:70:25: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   70 |         for(register ll i=1,a,b,c;i<=m;i++)
      |                         ^
a.cc:70:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   70 |         for(register ll i=1,a,b,c;i<=m;i++)
      |                             ^
a.cc:70:31: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   70 |         for(register ll i=1,a,b,c;i<=m;i++)
      |                               ^
a.cc:70:33: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   70 |         for(register ll i=1,a,b,c;i<=m;i++)
      |                                 ^
a.cc:77:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   77 |         for(register int i=1;i<=n;i++)
      |                          ^
a.cc:78:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   78 |                 for(register int j=1;j<=n;j++)
      |                                  ^
a.cc:79:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   79 |                         for(register int k=1;k<=n;k++)
      |                                          ^
a.cc:83:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   83 |         for(register int i=1;i<=n;i++)
      |                          ^
a.cc:84:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   84 |                 for(register int j=i+1;j<=n;j++)
      |                                  ^
a.cc:87:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   87 |         for(register int i=1;i<=n;i++)
      |                          ^
a.cc:88:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   88 |                 for(register int j=1;j<=n;j++)
      |                                  ^
a.cc:89:42: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   89 |                         for(register int k=1;k<=n;k++)
      |                                          ^
a.cc:93:25: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   93 |         for(register ll i=1,a,b;i<=q;i++)
      |                         ^
a.cc:93:29: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   93 |         for(register ll i=1,a,b;i<=q;i++)
      |                             ^
a.cc:93:31: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   93 |         for(register ll i=1,a,b;i<=q;i++)
      |                               ^