Language: C++

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O-fast")
#include<bits/stdc++.h>

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;
typedef pair < ll , ll > pll;

const double PI = acos(-1);
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
	

ll addMod(ll a, ll b){
	if(a + b >= MOD) return a + b - MOD;
	return a + b;
}

ll mulMod(ll a, ll b){
	return (a*b)%MOD;
}

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp,tmp);
	if(b%2 == 1) tmp = mulMod(tmp,a);
	return tmp;
}

ll GCD(ll a, ll b){
	if(a > b) return GCD(b,a);
	if(a == 0) return b;
	return GCD(b%a,a);
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

//////////////////////////////////////////////

const int N = 300;

int n,m,cap;
vii G[N + 5];
int ans[N + 5][N + 5];
bool vis[N + 5], vis2[N + 5];
int maxRem[N + 5];
int now, rem, cost, nxt, ww;
void pre(int st){
//	printf("start %d\n",st);
	memset(maxRem, 0, sizeof maxRem);
	memset(vis,0,sizeof vis);
	memset(vis2,0,sizeof vis2);
	priority_queue < pair < int , pii > > pq;
	while(!pq.empty()) pq.pop();
	pq.push(MP(0, MP(cap, st)));
	while(!pq.empty()){
		now = pq.top().SE.SE;
		cost = -pq.top().FI;
		rem = pq.top().SE.FI;
		pq.pop();
		if(maxRem[now] > rem && vis[now]) continue;
		if(vis2[now]) continue;
//		printf("now %d, cost %d, rem %d -> %d\n",now,cost,rem,ans[st][now]);
		if(!vis[now]){
			ans[st][now] = cost;
			vis[now] = true;
		}
		else{
			vis2[now] = true;
		}
		maxRem[now] = rem;
		
		FOR(i,G[now].size()){
			nxt = G[now][i].FI;
			ww = G[now][i].SE;
			if(!vis[nxt]){
				pq.push(MP(-(cost+1), MP(cap - ww, nxt)));
				if(rem >= ww) pq.push(MP(-cost, MP(rem-ww, nxt)));
			}
			else if(!vis2[nxt]){
				if(maxRem[nxt] < rem - ww && cost == ans[st][nxt]) pq.push(MP(-cost, MP(rem-ww, nxt)));
				if(maxRem[nxt] < cap - ww && cost+1 == ans[st][nxt]) pq.push(MP(-(cost+1), MP(cap - ww, nxt)));
			}
		}
	}
}

void solve(){
	memset(ans,-1,sizeof ans);
	REP(i,1,n){
		pre(i);
	}
}

int main(){
//	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ini(n);
	ini(m);
	ini(cap);
//	cin >> n >> m >> cap;
	int u,v,w;
	FOR(i,m){
		ini(u);
		ini(v);
		ini(w);
//		cin >> u >> v >> w;
		if(w > cap) continue;
		G[u].PB(MP(v,w));
		G[v].PB(MP(u,w));
	}
	solve();
	int q;
	ini(q);
//	cin >> q;
	while(q--){
		ini(u);
		ini(v);
//		cin >> u >> v;
//		cout << "ans ";
		printf("%d\n",ans[u][v]);
//		cout << ans[u][v] << endl;
	}
	return 0;
}

Compiler output:
a.cc:2:30: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
    2 | #pragma GCC optimize("O-fast")
      |                              ^
In file included from /usr/include/c++/14/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33,
                 from a.cc:3:
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:321:29: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  321 |   inline void __terminate() _GLIBCXX_USE_NOEXCEPT
      |                             ^~~~~~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h: In function 'void std::__terminate()':
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:323:82: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  323 |     void terminate() _GLIBCXX_USE_NOEXCEPT __attribute__ ((__noreturn__,__cold__));
      |                                                                                  ^
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:323:82: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h: At global scope:
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:543:29: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  543 |   __is_constant_evaluated() _GLIBCXX_NOEXCEPT
      |                             ^~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:582:3: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  582 |   _GLIBCXX_NOEXCEPT;
      |   ^~~~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:582:3: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:608:25: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  608 |   __glibcxx_assert_fail()
      |                         ^
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683:
/usr/include/assert.h:71:45: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
   71 |      __THROW __attribute__ ((__noreturn__)) __COLD;
      |                                             ^~~~~~
/usr/include/assert.h:71:45: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/assert.h:76:45: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
   76 |      __THROW __attribute__ ((__noreturn__)) __COLD;
      |                                             ^~~~~~
/usr/include/assert.h:76:45: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/assert.h:82:45: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
   82 |      __THROW __attribute__ ((__noreturn__)) __COLD;
      |                                             ^~~~~~
/usr/include/assert.h:82:45: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
In file included from /usr/include/c++/14/cctype:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:35:
/usr/include/ctype.h:80:40: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
   80 |      __THROW __attribute__ ((__const__));
      |                                        ^
/usr/include/ctype.h:80:40: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:82:40: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
   82 |      __THROW __attribute__ ((__const__));
      |                                        ^
/usr/include/ctype.h:82:40: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:84:40: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
   84 |      __THROW __attribute__ ((__const__));
      |                                        ^
/usr/include/ctype.h:84:40: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:108:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  108 | __exctype (isalnum);
      | ^~~~~~~~~
/usr/include/ctype.h:108:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:109:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  109 | __exctype (isalpha);
      | ^~~~~~~~~
/usr/include/ctype.h:109:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:110:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  110 | __exctype (iscntrl);
      | ^~~~~~~~~
/usr/include/ctype.h:110:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:111:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  111 | __exctype (isdigit);
      | ^~~~~~~~~
/usr/include/ctype.h:111:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:112:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  112 | __exctype (islower);
      | ^~~~~~~~~
/usr/include/ctype.h:112:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:113:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  113 | __exctype (isgraph);
      | ^~~~~~~~~
/usr/include/ctype.h:113:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:114:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  114 | __exctype (isprint);
      | ^~~~~~~~~
/usr/include/ctype.h:114:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:115:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  115 | __exctype (ispunct);
      | ^~~~~~~~~
/usr/include/ctype.h:115:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:116:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  116 | __exctype (isspace);
      | ^~~~~~~~~
/usr/include/ctype.h:116:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:117:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  117 | __exctype (isupper);
      | ^~~~~~~~~
/usr/include/ctype.h:117:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:118:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  118 | __exctype (isxdigit);
      | ^~~~~~~~~
/usr/include/ctype.h:118:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:122:30: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  122 | extern int tolower (int __c) __THROW;
      |                              ^~~~~~~
/usr/include/ctype.h:122:30: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:125:30: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  125 | extern int toupper (int __c) __THROW;
      |                              ^~~~~~~
/usr/include/ctype.h:125:30: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:130:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  130 | __exctype (isblank);
      | ^~~~~~~~~
/usr/include/ctype.h:130:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:135:42: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  135 | extern int isctype (int __c, int __mask) __THROW;
      |                                          ^~~~~~~
/usr/include/ctype.h:135:42: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:142:30: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  142 | extern int isascii (int __c) __THROW;
      |                              ^~~~~~~
/usr/include/ctype.h:142:30: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:146:30: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  146 | extern int toascii (int __c) __THROW;
      |                              ^~~~~~~
/usr/include/ctype.h:146:30: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:150:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  150 | __exctype (_toupper);
      | ^~~~~~~~~
/usr/include/ctype.h:150:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:151:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  151 | __exctype (_tolower);
      | ^~~~~~~~~
/usr/include/ctype.h:151:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:251:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  251 | __exctype_l (isalnum_l);
      | ^~~~~~~~~~~
/usr/include/ctype.h:251:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/include/ctype.h:252:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
  252 | __exctype_l (isalpha_l);
      | ^~~~~~~~~~~
/usr/include/ctype.h:252:1: error: argument to '-O' should be a non-negative integer, 'g', 's', 'z' or 'fast'
/usr/i