#include
#include
#include
using namespace std;
const int maxn = 105;
vector> graph[maxn];
int dist[maxn][10][500];
struct node {
int idx, shortest_distance, k_left, path_with_automation;
node () {}
node(int _idx, int _shortest_distance, int _k_left, int _path_with_automation) {
idx = _idx;
shortest_distance = _shortest_distance;
k_left = _k_left;
path_with_automation = _path_with_automation;
}
bool operator < (const node & tmp) const {
return shortest_distance > tmp.shortest_distance;
}
};
int main() {
int n, x;
cin >> n >> x;
int K, L;
cin >> K >> L;
int m;
cin >> m;
for(int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
graph[a].push_back(make_pair(b, c));
graph[b].push_back(make_pair(a, c));
}
for(int i = 0; i <= n; i++) {
for(int j = 0; j <= K; j++) {
for(int k = 0; k <= L; k++) {
dist[i][j][k] = 2e9;
}
}
}
priority_queue pq;
pq.push(node(1, 0, K, L));
dist[1][0][0] = 0;
while(!pq.empty()) {
node c = pq.top();
pq.pop();
int new_path = c.path_with_automation;
if(c.idx <= x and new_path > 0) {
new_path = 0;
}
if(new_path > 0) {
for(int i = 0; i < (int) graph[c.idx].size(); i++) {
int neighbour = graph[c.idx][i].first;
int weight = graph[c.idx][i].second;
if(new_path - weight >= 0 and c.shortest_distance < dist[neighbour][c.k_left][new_path - weight]) {
dist[neighbour][c.k_left][new_path - weight] = c.shortest_distance;
pq.push(node(neighbour, c.shortest_distance, c.k_left, new_path - weight));
}
}
new_path = 0;
}
for(int i = 0; i < (int) graph[c.idx].size(); i++) {
int neighbour = graph[c.idx][i].first;
int weight = graph[c.idx][i].second;
if(c.shortest_distance + weight < dist[neighbour][c.k_left][new_path]) {
dist[neighbour][c.k_left][new_path] = c.shortest_distance + weight;
pq.push(node(neighbour, c.shortest_distance + weight, c.k_left, new_path));
}
}
if(c.k_left > 0) {
new_path = L;
for(int i = 0; i < (int) graph[c.idx].size(); i++) {
int neighbour = graph[c.idx][i].first;
int weight = graph[c.idx][i].second;
if(new_path - weight >= 0 and c.shortest_distance < dist[neighbour][c.k_left - 1][new_path - weight]) {
dist[neighbour][c.k_left - 1][new_path - weight] = c.shortest_distance;
pq.push(node(neighbour, c.shortest_distance, c.k_left - 1, new_path - weight));
}
}
}
}
int result = 2e9;
for(int i = 0; i <= K; i++) {
for(int j = 0; j <= L; j++) {
result = min(result, dist[n][i][j]);
}
}
cout << result << endl;
return 0;
}