/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class HighwayExpressBus {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      while(true) {
        int c, n, m, s, d; cin >> c >> n >> m >> s >> d;
        s--; d--;
        if (c==0) return;

        vector<P> graph[(c+1)*n];
        int cost[(c+1)*n];
        rep(i, (c+1)*n) {
          cost[i] = INT_MAX/2;
        }

        while(m--) {
          int a, b, f; cin >> a >> b >> f;
          a--; b--;
          rep(i, c+1) {
            graph[a+i*n].emplace_back(b+i*n, f);
            graph[b+i*n].emplace_back(a+i*n, f);
          }
          rep(i, c) {
            graph[a+i*n].emplace_back(b+(i+1)*n, f/2);
            graph[b+i*n].emplace_back(a+(i+1)*n, f/2);
          }
        }

        priority_queue<P, vector<P>, greater<>> que;
        que.emplace(0, s);
        cost[s] = 0;
        while(!que.empty()) {
          auto p = que.top(); que.pop();
          if (p.first > cost[p.second]) continue;
          for(const auto& e: graph[p.second]) {
            if (cost[e.first] > p.first + e.second) {
              cost[e.first] = p.first + e.second;
              que.emplace(cost[e.first], e.first);
            }
          }
        }

        int ans = INT_MAX;
        rep(i, c+1) {
          chmin(ans, cost[d+n*i]);
        }
        cout << ans << endl;
      }

    }
};

signed main() {
  HighwayExpressBus solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
