Language: C++

#include <bits/stdc++.h>
 
using namespace std;
 
template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n, m, l;
		cin >> n >> m >> l;
		vector<vector<int>> d(n, vector<int>(n, 0x3f3f3f3f)), d2(n, vector<int>(n, 0x3f3f3f3f));
		for(int i=0; i < m; i++){
			int a, b, c;
			cin >> a >> b >> c;
			a--, b--;
        	d2[a][b] = d2[b][a] = c;
		}
		for(int k=0; k < n; k++){
			for(int i=0; i < n; i++){
				for(int j=0; j < n; j++){
					updmin(d2[i][j], d2[i][k] + d2[k][j]);
				}
			}
		}
      	for(int i=0; i < n; i++)for(int j=0; j < n; j++)if(d2[i][j] <= l)d[i][j] = 1;
		for(int k=0; k < n; k++){
			for(int i=0; i < n; i++){
				for(int j=0; j < n; j++){
					updmin(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
 
		int Q;
		cin >> Q;
		for(int q=0; q < Q; q++){
			int s, t;
			cin >> s >> t;
			if(d[s-1][t-1] == 0x3f3f3f3f)cout << -1 << "\n";
			else cout << d[s-1][t-1]-1 << "\n";				
		}
 
	
		return;
	};
};
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}
#include <bits/stdc++.h>
 
using namespace std;
 
template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}
 
template<class W>
 
class Solution {
public:
	void solve() {
		int n, m, l;
		cin >> n >> m >> l;
		vector<vector<int>> d(n, vector<int>(n, 0x3f3f3f3f)), d2(n, vector<int>(n, 0x3f3f3f3f));
		for(int i=0; i < m; i++){
			int a, b, c;
			cin >> a >> b >> c;
			a--, b--;
        	d2[a][b] = d2[b][a] = c;
		}
		for(int k=0; k < n; k++){
			for(int i=0; i < n; i++){
				for(int j=0; j < n; j++){
					updmin(d2[i][j], d2[i][k] + d2[k][j]);
				}
			}
		}
      	for(int i=0; i < n; i++)for(int j=0; j < n; j++)if(d2[i][j] <= l)d[i][j] = 1;
		for(int k=0; k < n; k++){
			for(int i=0; i < n; i++){
				for(int j=0; j < n; j++){
					updmin(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}
 
		int Q;
		cin >> Q;
		for(int q=0; q < Q; q++){
			int s, t;
			cin >> s >> t;
			if(d[s-1][t-1] == 0x3f3f3f3f)cout << -1 << "\n";
			else cout << d[s-1][t-1]-1 << "\n";				
		}
 
	
		return;
	};
};
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Compiler output:
a.cc:61:28: error: redefinition of 'template<class T> T updmax(T&, T)'
   61 | template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
      |                            ^~~~~~
a.cc:5:28: note: 'template<class T> T updmax(T&, T)' previously declared here
    5 | template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
      |                            ^~~~~~
a.cc:62:28: error: redefinition of 'template<class T> T updmin(T&, T)'
   62 | template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}
      |                            ^~~~~~
a.cc:6:28: note: 'template<class T> T updmin(T&, T)' previously declared here
    6 | template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}
      |                            ^~~~~~
a.cc:66:7: error: 'Solution' is not a template
   66 | class Solution {
      |       ^~~~~~~~
a.cc:8:7: note: previous declaration here
    8 | class Solution {
      |       ^~~~~~~~
a.cc:108:5: error: redefinition of 'int main()'
  108 | int main() {
      |     ^~~~
a.cc:50:5: note: 'int main()' previously defined here
   50 | int main() {
      |     ^~~~