Language: C++

#include <bits/stdc++.h>
using namespace std;
const int maxn = 310;
const long long INF = 1e13;
long long a[maxn][maxn], d[maxn][maxn], b[maxn][maxn];
int n, m, L;

int main(){
	cin >> n >> m >> L;
	int x, y, z;
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			if(i==j) b[i][j] = a[i][j] = 0;
			else b[i][j] = a[i][j] = INF;
	for(int i=1; i<=m; i++){
		cin >> x >> y >> z;
		if(z<=L)
			a[y][x] = a[x][y] = min(a[x][y], z);
	}
	for(int k=1; k<=n; k++) // 求出各个点之间的最短路径 
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
	for(int i=1; i<=n; i++)
		for(int j=1; j<=n; j++)
			if(i!=j && d[i][j]<=L) //当成是加一次油 
				b[i][j] = 1;
	// 以加油次数为权值（b[i][j]），再求一次floyd，就可以求出最小加油次数
	for(int k=1; k<=n; k++)
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				b[i][j] = min(b[i][j], b[i][k]+b[k][j]);
	int q;
	cin >> q;
	for(int i=1; i<=q; i++){
		cin >> x >> y;
		if(b[x][y]>=INF)
			cout << -1 << endl;
		else
			cout << b[x][y]-1 << endl;  // 不超过L时，默认为1，实际要减去1 
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:48: error: no matching function for call to 'min(long long int&, int&)'
   18 |                         a[y][x] = a[x][y] = min(a[x][y], z);
      |                                             ~~~^~~~~~~~~~~~
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:18:48: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   18 |                         a[y][x] = a[x][y] = min(a[x][y], z);
      |                                             ~~~^~~~~~~~~~~~
/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:18:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   18 |                         a[y][x] = a[x][y] = min(a[x][y], z);
      |                                             ~~~^~~~~~~~~~~~