Language: C++

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
short n, m, k, p, dist[6007][2017], c[3000]; bool u[3000];
vector<string>v; string a[3000], b[3000], s1, s2; vector<pair<int, int>>x[7000];
int s(string Y) { return lower_bound(v.begin(), v.end(), Y) - v.begin(); }
int main() {
	while (true) {
		cin >> m >> k >> p; p *= 10; if (m + k + p == 0)return 0; v.clear(); cin >> s1 >> s2;
		for (int i = 0; i < m; i++) { cin >> a[i] >> b[i] >> c[i]; v.push_back(a[i]); v.push_back(b[i]); }
		sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); n = v.size();
		for (int i = 0; i < n; i++) { x[i].clear(); u[i] = false; for (int j = 0; j <= p; j++)dist[i][j] = 1e9; }
		for (int i = 0; i < m; i++) { int pos1 = s(a[i]), pos2 = s(b[i]); x[pos1].push_back(make_pair(pos2, c[i])); x[pos2].push_back(make_pair(pos1, c[i])); }
		priority_queue<tuple<short, short, short>, vector<tuple<short, short, short>>, greater<tuple<short, short, short>>>Q;
		for (int i = 0; i < k; i++) { string U; cin >> U; u[s(U)] = true; }
		
		Q.push(make_tuple(0, s(s1), p)); dist[s(s1)][p] = 0;
		while (!Q.empty()) {
			int a1 = get<0>(Q.top()), a2 = get<1>(Q.top()), a3 = get<2>(Q.top()); Q.pop();
			for (pair<int, int>i : x[a2]) {
				int cap = a3 - i.second; if (cap < 0)continue; if (u[i.first] == true)cap = p;
				if (dist[i.first][cap] > dist[a2][a3] + i.second) {
					dist[i.first][cap] = dist[a2][a3] + i.second; Q.push(make_tuple(dist[i.first][cap], i.first, cap));
				}
			}
		}
		int maxn = 1e9; for (int i = 0; i <= p; i++)maxn = min(maxn, dist[s(s2)][i]); if (maxn > 1e8)maxn = -1;
		cout << maxn << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:116: warning: overflow in conversion from 'double' to 'short int' changes value from '1.0e+9' to '32767' [-Woverflow]
   16 |                 for (int i = 0; i < n; i++) { x[i].clear(); u[i] = false; for (int j = 0; j <= p; j++)dist[i][j] = 1e9; }
      |                                                                                                                    ^~~
a.cc:31:71: error: no matching function for call to 'min(int&, short int&)'
   31 |                 int maxn = 1e9; for (int i = 0; i <= p; i++)maxn = min(maxn, dist[s(s2)][i]); if (maxn > 1e8)maxn = -1;
      |                                                                    ~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:31:71: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'short int')
   31 |                 int maxn = 1e9; for (int i = 0; i <= p; i++)maxn = min(maxn, dist[s(s2)][i]); if (maxn > 1e8)maxn = -1;
      |                                                                    ~~~^~~~~~~~~~~~~~~~~~~~~~
/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,
                 from a.cc:2:
/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:31:71: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   31 |                 int maxn = 1e9; for (int i = 0; i <= p; i++)maxn = min(maxn, dist[s(s2)][i]); if (maxn > 1e8)maxn = -1;
      |                                                                    ~~~^~~~~~~~~~~~~~~~~~~~~~