Problem:
Problem D: Long Distance Taxi

A taxi driver, Nakamura, was so delighted because he got a passenger who wanted to go to a
city thousands of kilometers away. However, he had a problem. As you may know, most taxis in
Japan run on liquefied petroleum gas (LPG) because it is cheaper than gasoline. There are more
than 50,000 gas stations in the country, but less than one percent of them sell LPG. Although
the LPG tank of his car was full, the tank capacity is limited and his car runs 10 kilometer per
liter, so he may not be able to get to the destination without filling the tank on the way. He
knew all the locations of LPG stations.
Your task is to write a program that finds the best way from the current location to the destination without running out of gas.

Input

The input consists of several datasets, and each dataset is in the following format.

N M cap

src dest

c1,1 c1,2 d1

c2,1 c2,2 d2

.

.

.

cN,1 cN,2 dN

s1

s2

.

.

.

sM

The first line of a dataset contains three integers (N, M, cap), where N is the number of roads
(1 ≤ N ≤ 3000),M is the number of LPG stations (1≤ M ≤ 300), and cap is the tank capacity
(1 ≤ cap ≤ 200) in liter. The next line contains the name of the current city (src) and the name
of the destination city (dest). The destination city is always different from the current city.
The following N lines describe roads that connect cities. The road i (1 ≤ i ≤ N) connects two
different cities ci,1 and ci,2 with an integer distance di (0 < di ≤ 2000) in kilometer, and he can
go from either city to the other. You can assume that no two different roads connect the same
pair of cities. The columns are separated by a single space. The next M lines (s1,s2,...,sM) indicate the names of the cities with LPG station.
You can assume that a city with LPG station has at least one road.

The name of a city has no more than 15 characters. Only English alphabet ('A' to 'Z' and 'a'
to 'z', case sensitive) is allowed for the name.

A line with three zeros terminates the input.

Output

For each dataset, output a line containing the length (in kilometer) of the shortest possible
journey from the current city to the destination city. If Nakamura cannot reach the destination,
output "-1" (without quotation marks). You must not output any other characters.
The actual tank capacity is usually a little bit larger than that on the specification sheet, so
you can assume that he can reach a city even when the remaining amount of the gas becomes
exactly zero. In addition, you can always fill the tank at the destination so you do not have to
worry about the return trip.

Sample Input

6 3 34
Tokyo Kyoto
Tokyo Niigata 335
Tokyo Shizuoka 174
Shizuoka Nagoya 176
Nagoya Kyoto 195
Toyama Niigata 215
Toyama Kyoto 296
Nagoya
Niigata
Toyama
6 3 30
Tokyo Kyoto
Tokyo Niigata 335
Tokyo Shizuoka 174
Shizuoka Nagoya 176
Nagoya Kyoto 195
Toyama Niigata 215
Toyama Kyoto 296
Nagoya
Niigata
Toyama
0 0 0

Output for the Sample Input

846
-1

Solution in C++11 (judge verdict: Accepted)

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>
#include <tuple>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MT make_tuple
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1e9;

struct Edge{
  int to, cost;

  Edge(int t, int c): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
};
typedef vector< vector<Edge> > Graph;

int N, M, C, SZ;
vector<Edge> G[6010];

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while(cin>>N>>M>>C,N){
	map<string,int> cor;
	string src, dest; cin >> src >> dest;
	SZ = 0;
	cor[src] = SZ++;
	cor[dest] = SZ++;
	C *= 10;
	REP(i,6010) G[i].clear();
	REP(i,N){
	  string s1, s2; int d;
	  cin >> s1 >> s2 >> d;
	  if(!cor.count(s1)) cor[s1] = SZ++;
	  if(!cor.count(s2)) cor[s2] = SZ++;
	  int u = cor[s1], v = cor[s2];
	  G[u].PB(Edge(v,d));
	  G[v].PB(Edge(u,d));
	}

	set<int> LPG;
	REP(i,M){
	  string s; cin >> s;
	  if(!cor.count(s)) continue;
	  LPG.insert(cor[s]);
	}

	typedef tuple<int,int,int> Node;
	priority_queue<Node, vector<Node>, greater<Node> > pq;
	VVI dist(SZ+10, VI(C+10,INF));
	dist[0][C] = 0;
	pq.push(MT(0,0,C));

	int ans = INF;
	while(!pq.empty()){
	  auto tp = pq.top(); pq.pop();
	  int c, v, f;
	  tie(c,v,f) = tp;

	  if(v == 1){
		ans = c; break;
	  }
	  if(dist[v][f] < c) continue;
	  for(auto& e: G[v]){
		int d = e.cost;
		if(f < d) continue;
		int nf = LPG.count(e.to)? C: f-d;
		if(dist[e.to][nf] > dist[v][f] + d){
		  dist[e.to][nf] = dist[v][f] + d;
		  pq.push(MT(dist[e.to][nf], e.to, nf));
		}
	  }
	}

	cout << (ans==INF? -1: ans) << endl;
  }

  return 0;
}