Language: C++

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>

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:26:19: error: 'acos' was not declared in this scope
   26 | const double PI = acos(-1);
      |                   ^~~~