Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
const int INF = 1000000000;


class DP{
public:
	int cost, n, x;
	
	DP(){}
	DP(int cc, int nn, int xx){
		cost = cc;x=xx;n=nn;
	}
	
	bool operator< (const DP &opp) const {
		return cost>opp.cost;
	}
};
int memo[105][105];
int N, M, L, K, A, H;
main(){
	int i,j;
	while(cin >> N >> M >> L >> K >> A >> H, N){
		vector< vector<pii> > g(N);
		set<int> freeze;
		REP(i, L){
			int x;
			cin >> x;
			freeze.insert(x);
		}
		REP(i, K){
			int x, y, t;
			cin >> x >> y >> t;
			g[x].push_back(pii(y, t));
			g[y].push_back(pii(x, t));
		}
		REP(i, N)REP(j, M+1) memo[i][j] = INF;
		priority_queue<DP> dp;
		DP S;
		dp.push(DP(0, A, M));
		while(!dp.empty()){
			S = dp.top();
			dp.pop();
			#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
const int INF = 1000000000;


class DP{
public:
	int cost, n, x;
	
	DP(){}
	DP(int cc, int nn, int xx){
		cost = cc;x=xx;n=nn;
	}
	
	bool operator< (const DP &opp) const {
		return cost>opp.cost;
	}
};
int memo[105][105];
int N, M, L, K, A, H;
main(){
	int i,j;
	while(cin >> N >> M >> L >> K >> A >> H, N){
		vector< vector<pii> > g(N);
		set<int> freeze;
		REP(i, L){
			int x;
			cin >> x;
			freeze.insert(x);
		}
		REP(i, K){
			int x, y, t;
			cin >> x >> y >> t;
			g[x].push_back(pii(y, t));
			g[y].push_back(pii(x, t));
		}
		REP(i, N)REP(j, M+1) memo[i][j] = INF;
		priority_queue<DP> dp;
		DP S;
		dp.push(DP(0, A, M));
		while(!dp.empty()){
			S = dp.top();
			dp.pop();
			if(memo[S.n][S.x] < S.cost) continue;
			FOR(it, g[S.n]){
				DP T=S;
				T.x -= it->second;
				if(T.x < 0) continue;
				T.n = it->first;
				T.cost += it->second;
				if(memo[T.n][T.x] > T.cost){
					memo[T.n][T.x] = T.cost;
					dp.push(T);
				}
				if(freeze.count(T.n)){
					while(++T.x <= M){
						T.cost ++;
						if(memo[T.n][T.x] > T.cost){
							memo[T.n][T.x] = T.cost;
							dp.push(T);
						}
					}
				}
			}
		}
		if(S.n == H) cout << S.cost << endl;
		else cout << "Help!" << endl;
	}
	return 0;
}

			if(S.n == H) break;
			FOR(it, g[S.n]){
				DP T=S;
				T.x -= it->second;
				if(T.x < 0) continue;
				T.n = it->first;
				T.cost += it->second;
				if(memo[T.n][T.x] > T.cost){
					memo[T.n][T.x] = T.cost;
					dp.push(T);
				}
				if(freeze.count(T.n)){
					while(++T.x <= M){
						T.cost ++;
						if(memo[T.n][T.x] > T.cost){
							memo[T.n][T.x] = T.cost;
							dp.push(T);
						}
					}
				}
			}
		}
		if(S.n == H) cout << S.cost << endl;
		else cout << "Help!" << endl;
	}
	return 0;
}

Compiler output:
a.cc:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:94:7: error: expected ';' before '{' token
   94 | main(){
      |       ^
      |       ;
a.cc:147:38: error: conversion from 'DP' to non-scalar type 'main()::DP' requested
  147 |                                 DP T=S;
      |                                      ^
a.cc:154:48: error: no matching function for call to 'std::priority_queue<DP>::push(main()::DP&)'
  154 |                                         dp.push(T);
      |                                         ~~~~~~~^~~
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = DP; _Sequence = std::vector<DP, std::allocator<DP> >; _Compare = std::less<DP>; value_type = DP]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:30: note:   no known conversion for argument 1 from 'main()::DP' to 'const std::priority_queue<DP>::value_type&' {aka 'const DP&'}
  736 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = DP; _Sequence = std::vector<DP, std::allocator<DP> >; _Compare = std::less<DP>; value_type = DP]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:25: note:   no known conversion for argument 1 from 'main()::DP' to 'std::priority_queue<DP>::value_type&&' {aka 'DP&&'}
  744 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:161:64: error: no matching function for call to 'std::priority_queue<DP>::push(main()::DP&)'
  161 |                                                         dp.push(T);
      |                                                         ~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = DP; _Sequence = std::vector<DP, std::allocator<DP> >; _Compare = std::less<DP>; value_type = DP]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:30: note:   no known conversion for argument 1 from 'main()::DP' to 'const std::priority_queue<DP>::value_type&' {aka 'const DP&'}
  736 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = DP; _Sequence = std::vector<DP, std::allocator<DP> >; _Compare = std::less<DP>; value_type = DP]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:25: note:   no known conversion for argument 1 from 'main()::DP' to 'std::priority_queue<DP>::value_type&&' {aka 'DP&&'}
  744 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~