#include <bits/stdc++.h>                                                                                        
                                                                                                                
using namespace std;                                                                                            
                                                                                                                
struct Edge {                                                                                                   
    int to, cost;                                                                                               
};                                                                                                              
                                                                                                                
struct Node {                                                                                                   
    int ticket;                                                                                                 
    int cost;                                                                                                   
    vector<Edge> route;                                                                                         
                                                                                                                
    bool operator<(const Node &r) const {                                                                       
        return cost < r.cost;                                                                                   
    }                                                                                                           
};                                                                                                              
                                                                                                                
int main() {                                                                                                    
                                                                                                                
    int c, n, m, s, d;                                                                                          
                                                                                                                
    while(cin >> c >> n >> m >> s >> d, c | n | m | s | d) {                                                    
                                                                                                                
        Node node[n];                                                                                           
        int cost[n][c + 1];                                                                                     
        priority_queue<Node, vector<Node> > q;                                                                  
                                                                                                                
        for(int i = 0, a, b, f; i < m; ++i) {                                                                   
            cin >> a >> b >> f;                                                                                 
            node[a - 1].route.push_back((Edge){b - 1, f});                                                      
            node[b - 1].route.push_back((Edge){a - 1, f});                                                      
        }                                                                                                       
                                                                                                                
        for(int i = 0; i < n; ++i) {                                                                            
            for(int j = 0; j < c + 1; ++j) {                                                                    
                cost[i][j] = 1 << 24;                                                                           
            }                                                                                                   
        }                                                                                                       
                                                                                                                
        for(int i = 0; i < c + 1; ++i) {                                                                        
            cost[s - 1][i] = 0;                                                                                 
        }                                                                                                       
                                                                                                                
        node[s - 1].ticket = c;                                                                                 
        node[s - 1].cost = 0;                                                                                   
                                                                                                                
        q.push(node[s - 1]);                                                                                    
                                                                                                                
        while(!q.empty()) {                                                                                     
                                                                                                                
            Node now = q.top(); q.pop();                                                                        
                                                                                                                
            for(int i = 0; i < now.route.size(); ++i) {                                                         
                                                                                                                
                Node next = node[now.route[i].to];                                                              
                                                                                                                
                if(now.cost + now.route[i].cost < cost[now.route[i].to][now.ticket]) {                          
                    next.cost = cost[now.route[i].to][now.ticket] = now.cost + now.route[i].cost;               
                    next.ticket = now.ticket;                                                                   
                    q.push(next);                                                                               
                }                                                                                               
                                                                                                                
                if(now.ticket > 0 && now.cost + now.route[i].cost / 2 < cost[now.route[i].to][now.ticket - 1]) {
                    next.cost = cost[now.route[i].to][now.ticket - 1] = now.cost + now.route[i].cost / 2;       
                    next.ticket = now.ticket - 1;                                                               
                    q.push(next);                                                                               
                }                                                                                               
                                                                                                                
            }                                                                                                   
                                                                                                                
        }                                                                                                       
                                                                                                                
        int min_cost = 1 << 24;                                                                                 
        for(int i = 0; i < c + 1; ++i) {                                                                        
            min_cost = min(min_cost, cost[d - 1][i]);                                                           
        }                                                                                                       
                                                                                                                
        cout << min_cost << endl;                                                                               
                                                                                                                
    }                                                                                                           
                                                                                                                
}                                                                                                               