Language: C++

#define pb push_back
#define all(a) (a).begin(),(a).end()
#define f first
#define s second
#define foreach(it, c) for(__typeof__((c).begin()) it=(c).begin();it!=(c).end();it++)
 
#define MAX_V 8000
#define INF 100000000
 
using namespace std;
 
struct edge{int to, cost; };
typedef pair<int, int> P;
typedef pair<int,P>P3;
//dist,to,cap
 
int V,d[MAX_V][2001],cap;
string dest;
vector<edge>G[MAX_V];
set<int>st;
 map<string,int>vnum;
 
 
void dijkstra(int s){
  priority_queue<P3, vector<P3>, greater<P3> >que;
  fill(d[0], d[MAX_V], INF);
  d[s][cap*10] = 0;
  que.push(P3(0, P(s,cap*10)));
 
  while(!que.empty()){
    P3 p = que.top();
    que.pop();
    int v = p.s.f;
  	
    if(d[v][p.s.s] < p.first)continue;

  	d[v][p.s.s]=p.f;
  	
  	if(v==vnum[dest]){
  		cout << p.f << endl;
  		return ;
  	}
  	
  	if(st.find(v)!=st.end()){	
  		p.s.s=cap*10;
  		d[v][p.s.s]=p.f;
  	}
  	
    for(int i=0; i < G[v].size(); i++){
      edge e = G[v][i];
      int nc=p.s.s-e.cost;

      if(nc>=0 && d[e.to][nc] > d[v][p.s.s]+e.cost){
   		 d[e.to][nc] = d[v][p.s.s]+e.cost;
   		 que.push(P3(d[e.to][nc], P(e.to,nc)));
      }
    }
  }
	cout << -1 << endl;
}
 
int main(void){
 
  int n,m,cost;
  string src,dest,to,from;
  vector<string>node;
  vector<string>F,t;
  vector<int>c;
 
  while(cin >> n >> m >> cap,n|m|cap){
    node.clear();
    F.clear();
    t.clear();
    c.clear();
    st.clear();
  	vnum.clear();
  	
    cin >> src >> dest;
     
    node.pb(src);
    node.pb(dest);
 
    for(int i=0;i<n;i++){
      cin >> from >> to >> cost;
      F.pb(from);
      t.pb(to);
      c.pb(cost);
      node.pb(from);
      node.pb(to);
    }
 
    sort(all(node));
    node.erase(unique(all(node)),node.end());
    V=node.size();
 
 
    for(int i=0;i<V;i++){
      vnum[node[i]]=i;
    }
     
    for(int i=0;i<V;i++)G[i].clear();    
 
    for(int i=0;i<n;i++){
      edge e;
      e.to=vnum[t[i]];
      e.cost=c[i];
      G[vnum[F[i]]].pb(e);
 
      e.to=vnum[F[i]];
      G[vnum[t[i]]].pb(e);
    }
 
 
    for(int i=0;i<m;i++){
      string name;
      cin >> name;
      st.insert(vnum[name]);
    }
 
    dijkstra(vnum[src]);
 
  }
 
  return 0;
}

Compiler output:
a.cc:13:9: error: 'pair' does not name a type
   13 | typedef pair<int, int> P;
      |         ^~~~
a.cc:14:9: error: 'pair' does not name a type
   14 | typedef pair<int,P>P3;
      |         ^~~~
a.cc:18:1: error: 'string' does not name a type
   18 | string dest;
      | ^~~~~~
a.cc:19:1: error: 'vector' does not name a type
   19 | vector<edge>G[MAX_V];
      | ^~~~~~
a.cc:20:1: error: 'set' does not name a type
   20 | set<int>st;
      | ^~~
a.cc:21:2: error: 'map' does not name a type
   21 |  map<string,int>vnum;
      |  ^~~
a.cc: In function 'void dijkstra(int)':
a.cc:25:3: error: 'priority_queue' was not declared in this scope
   25 |   priority_queue<P3, vector<P3>, greater<P3> >que;
      |   ^~~~~~~~~~~~~~
a.cc:1:1: note: 'std::priority_queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
  +++ |+#include <queue>
    1 | #define pb push_back
a.cc:25:18: error: 'P3' was not declared in this scope
   25 |   priority_queue<P3, vector<P3>, greater<P3> >que;
      |                  ^~
a.cc:25:22: error: 'vector' was not declared in this scope
   25 |   priority_queue<P3, vector<P3>, greater<P3> >que;
      |                      ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | #define pb push_back
a.cc:25:32: error: expected primary-expression before ',' token
   25 |   priority_queue<P3, vector<P3>, greater<P3> >que;
      |                                ^
a.cc:25:34: error: 'greater' was not declared in this scope
   25 |   priority_queue<P3, vector<P3>, greater<P3> >que;
      |                                  ^~~~~~~
a.cc:25:46: error: expected primary-expression before '>' token
   25 |   priority_queue<P3, vector<P3>, greater<P3> >que;
      |                                              ^
a.cc:25:47: error: 'que' was not declared in this scope
   25 |   priority_queue<P3, vector<P3>, greater<P3> >que;
      |                                               ^~~
a.cc:26:3: error: 'fill' was not declared in this scope
   26 |   fill(d[0], d[MAX_V], INF);
      |   ^~~~
a.cc:28:18: error: 'P' was not declared in this scope
   28 |   que.push(P3(0, P(s,cap*10)));
      |                  ^
a.cc:31:7: error: expected ';' before 'p'
   31 |     P3 p = que.top();
      |       ^~
      |       ;
a.cc:33:13: error: 'p' was not declared in this scope
   33 |     int v = p.s.f;
      |             ^
a.cc:39:15: error: 'vnum' was not declared in this scope; did you mean 'enum'?
   39 |         if(v==vnum[dest]){
      |               ^~~~
      |               enum
a.cc:39:20: error: 'dest' was not declared in this scope
   39 |         if(v==vnum[dest]){
      |                    ^~~~
a.cc:40:17: error: 'cout' was not declared in this scope
   40 |                 cout << p.f << endl;
      |                 ^~~~
a.cc:1:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | #define pb push_back
a.cc:40:32: error: 'endl' was not declared in this scope
   40 |                 cout << p.f << endl;
      |                                ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | #define pb push_back
a.cc:44:12: error: 'st' was not declared in this scope; did you mean 'std'?
   44 |         if(st.find(v)!=st.end()){
      |            ^~
      |            std
a.cc:49:22: error: 'G' was not declared in this scope
   49 |     for(int i=0; i < G[v].size(); i++){
      |                      ^
a.cc:59:9: error: 'cout' was not declared in this scope
   59 |         cout << -1 << endl;
      |         ^~~~
a.cc:59:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:59:23: error: 'endl' was not declared in this scope
   59 |         cout << -1 << endl;
      |                       ^~~~
a.cc:59:23: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc: In function 'int main()':
a.cc:65:3: error: 'string' was not declared in this scope
   65 |   string src,dest,to,from;
      |   ^~~~~~
a.cc:1:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
  +++ |+#include <string>
    1 | #define pb push_back
a.cc:66:3: error: 'vector' was not declared in this scope
   66 |   vector<string>node;
      |   ^~~~~~
a.cc:66:3: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:66:17: error: 'node' was not declared in this scope
   66 |   vector<string>node;
      |                 ^~~~
a.cc:67:17: error: 'F' was not declared in this scope
   67 |   vector<string>F,t;
      |                 ^
a.cc:67:19: error: 't' was not declared in this scope
   67 |   vector<string>F,t;
      |                   ^
a.cc:68:10: error: expected primary-expression before 'int'
   68 |   vector<int>c;
      |          ^~~
a.cc:70:9: error: 'cin' was not declared in this scope
   70 |   while(cin >> n >> m >> cap,n|m|cap){
      |         ^~~
a.cc:70:9: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:74:5: error: 'c' was not declared in this scope
   74 |     c.clear();
      |     ^
a.cc:75:5: error: 'st' was not declared in this scope; did you mean 'std'?
   75 |     st.clear();
      |     ^~
      |     std
a.cc:76:9: error: 'vnum' was not declared in this scope; did you mean 'enum'?
   76 |         vnum.clear();
      |         ^~~~
      |         enum
a.cc:78:12: error: 'src' was not declared in this scope
   78 |     cin >> src >> dest;
      |            ^~~
a.cc:78:19: error: 'dest' was not declared in this scope
   78 |     cin >> src >> dest;
      |                   ^~~~
a.cc:84:14: error: 'from' was not declared in this scope
   84 |       cin >> from >> to >> cost;
      |              ^~~~
a.cc:84:22: error: 'to' was not declared in this scope
   84 |       cin >> from >> to >> cost;
      |                      ^~
a.cc:92:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   92 |     sort(all(node));
      |     ^~~~
      |     short
a.cc:93:16: error: 'unique' was not declared in this scope
   93 |     node.erase(unique(all(node)),node.end());
      |                ^~~~~~
a.cc:101:25: error: 'G' was not declared in this scope
  101 |     for(int i=0;i<V;i++)G[i].clear();
      |                         ^
a.cc:107:7: error: 'G' was not declared in this scope
  107 |       G[vnum[F[i]]].pb(e);
      |       ^
a.cc:115:13: error: expected ';' before 'name'
  115 |       string name;
      |             ^~~~~
      |             ;
a.cc:116:14: error: 'name' was not declared in this scope
  116 |       cin >> name;
      |              ^~~~