Language: C++

#include <queue>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
struct edge {
	int to, cost;
	edge(int to_, int cost_) : to(to_), cost(cost_) {};
};
bool operator<(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}
template<class Type>
std::vector<Type> shortest_path(std::vector<std::vector<edge> > &G, int s) {
	std::priority_queue<edge> que; que.push(edge(s, 0));
	std::vector<Type> ret(G.size(), std::numeric_limits<Type>::max()); ret[s] = 0;
	while (!que.empty()) {
		edge u = que.top(); que.pop();
		for (edge e : G[u.to]) {
			if (ret[e.to] > ret[u.to] + e.cost) {
				ret[e.to] = ret[u.to] + e.cost;
				que.push(edge(e.to, -ret[e.to]));
			}
		}
	}
	return ret;
}
int n, m, d, e;
int main() {
	while (cin >> n >> m, n) {
		string s, t, g;
		cin >> s >> t >> g;
		vector<string> a(m), b(m), r; vector<int> x(m);
		for (int i = 0; i < m; i++) {
			cin >> a[i] >> b[i] >> d >> e;
			x[i] = d / 40 + e;
			r.push_back(a[i]);
			r.push_back(b[i]);
		}
		sort(r.begin(), r.end());
		r.erase(unique(r.begin(), r.end()), r.end());
		int sp = lower_bound(r.begin(), r.end(), s) - r.begin();
		int tp = lower_bound(r.begin(), r.end(), t) - r.begin();
		int gp = lower_bound(r.begin(), r.end(), g) - r.begin();
		vector<vector<edge> > G(n);
		for (int i = 0; i < m; i++) {
			int ptr1 = lower_bound(r.begin(), r.end(), a[i]) - r.begin();
			int ptr2 = lower_bound(r.begin(), r.end(), b[i]) - r.begin();
			G[ptr1].push_back(edge(ptr2, x[i]));
			G[ptr2].push_back(edge(ptr1, x[i]));
		}
		int w1 = shortest_path<int>(G, sp)[tp];
		int w2 = shortest_path<int>(G, tp)[gp];
		cout << w1 + w2 << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'std::vector<_Tp> shortest_path(std::vector<std::vector<edge> >&, int)':
a.cc:16:46: error: 'numeric_limits' is not a member of 'std'
   16 |         std::vector<Type> ret(G.size(), std::numeric_limits<Type>::max()); ret[s] = 0;
      |                                              ^~~~~~~~~~~~~~
a.cc:16:65: error: expected primary-expression before '>' token
   16 |         std::vector<Type> ret(G.size(), std::numeric_limits<Type>::max()); ret[s] = 0;
      |                                                                 ^
a.cc:16:71: error: no matching function for call to 'max()'
   16 |         std::vector<Type> ret(G.size(), std::numeric_limits<Type>::max()); ret[s] = 0;
      |                                                                  ~~~~~^~
In file included from /usr/include/c++/14/deque:62,
                 from /usr/include/c++/14/queue:62,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 0 provided
a.cc: In function 'int main()':
a.cc:40:17: error: 'sort' was not declared in this scope; did you mean 'short'?
   40 |                 sort(r.begin(), r.end());
      |                 ^~~~
      |                 short
a.cc:41:25: error: 'unique' was not declared in this scope
   41 |                 r.erase(unique(r.begin(), r.end()), r.end());
      |                         ^~~~~~