// AOJ 0212 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0212)
#include <cstdio>
#include <algorithm>
#include <limits>
#include <queue>
#include <utility>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

constexpr int MAX_N = 100, INF = std::numeric_limits<int>::max()>>2;

using P = std::pair<int, std::pair<int, int>>;

struct edge
{
  int to, cost;

  edge( int to, int cost )
  : to(to), cost(cost)
  {}
};

int c, n, m, s, d;
std::vector<edge> G[MAX_N];
int dp[MAX_N][11];

int main()
{
  while( scanf( "%d%d%d%d%d", &c, &n, &m, &s, &d ), c|n|m|s|d )
  {
    --s; --d;
    
    rep( i, n )
      G[i].clear();

    rep( i, m )
    {
      int a, b, f;
      scanf( "%d%d%d", &a, &b, &f );
      --a; --b;
      G[a].emplace_back( edge( b, f ) );
      G[b].emplace_back( edge( a, f ) );
    }

    std::fill( (int*)dp, (int*)(dp+n), INF );
    
    std::priority_queue<P, std::vector<P>, std::greater<P>> pque;
    pque.push( P( 0, std::make_pair( s, 0 ) ) );
    while( !pque.empty() )
    {
      P p = pque.top(); pque.pop();
      int dist = p.first, v = p.second.first, ticket = p.second.second;

      if( dist > dp[v][ticket] )
        continue;

      for( auto e : G[v] )
      {
        if( dp[e.to][ticket] > dist+e.cost )
        {
          dp[e.to][ticket] = dist+e.cost;
          pque.push( P( dp[e.to][ticket], std::make_pair( e.to, ticket ) ) );
        }
        if( ticket < 10 && dp[e.to][ticket+1] > dist+e.cost/2 )
        {
          dp[e.to][ticket+1] = dist+e.cost/2;
          pque.push( P( dp[e.to][ticket+1], std::make_pair( e.to, ticket+1 ) ) );
        }
      }
    }

    printf( "%d\n", dp[d][c] );
  }

  return 0;
}
