Go: package main

import (
	"container/heap"
	"fmt"
)

type Node struct {
	NowPosition          int
	DiscountTicketTCount int
	Amount               int
}

type PriorityQueueNode []*Node

func (pq PriorityQueueNode) Len() int {
	return len(pq)
}

func (pq PriorityQueueNode) Less(i, j int) bool {
	return pq[i].Amount < pq[j].Amount
}

func (pq PriorityQueueNode) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueueNode) Push(node interface{}) {
	*pq = append(*pq, node.(*Node))
}

func (pq *PriorityQueueNode) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

type Point struct {
	NextPoint int
	Fee       int
}

type Memo struct {
	NowPoint             int
	DiscountTicketTCount int
}

func main() {
	var c, n, m, s, d int
	var a, b, f int

	for {
		fmt.Scan(&c, &n, &m, &s, &d)
		if c == 0 && n == 0 && m == 0 && s == 0 && d == 0 {
			break
		}
		s--
		d--
		pointMap := make([][]Point, n)
		for i := 0; i < n; i++ {
			pointMap[i] = make([]Point, 0)
		}
		for i := 0; i < m; i++ {
			fmt.Scan(&a, &b, &f)
			a--
			b--
			pointMap[a] = append(pointMap[a], Point{NextPoint: b, Fee: f})
			pointMap[b] = append(pointMap[b], Point{NextPoint: a, Fee: f})
		}
		pq := make(PriorityQueueNode, 0)
		start := Node{NowPosition: s, DiscountTicketTCount: c, Amount: 0}
		heap.Push(&pq, &start)
		memo := make(map[Memo]struct{})
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			memo[Memo{NowPoint: now.NowPosition, DiscountTicketTCount: now.DiscountTicketTCount}] = struct{}{}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if _, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok {
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if _, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok {
						heap.Push(&pq, next)
					}
				}
			}
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define INF (1<<29)//INF
#define F first
#define S second
#define VS vector<string>
#define VI vector<int>
#define REPI(i,s,n) for(int i=s;i<n;i++)//sからn未満の間iを回す
#define REPJ(j,s,n) for(int j=s;j<n;j++)//sからn未満の間iを回す
#define RREPI(i,s,n) for(int i=s;i>=n;i--)//sからn以下の間iを回す
#define RREPJ(j,s,n) for(int j=s;j>=n;j--)//sからn以下の間jを回す
#define ALL(a) a.begin(),a.end()//ソートとかに使える sort(ALL(vec))のように
#define SET(a,c) memset(a,c,sizeof(a));//aをc（0or1）で初期化する
#define DEBUGONE(x) cout<<#x<<" : "<<x<<endl;//デバックで一つの変数を表示
#define DEBUGTWO(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl;//デバックで二つの変数を表示
#define DEBUGTHREE(x,y,z) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl;//デバックで三つの変数を表示
#define OUTONE(x) cout<<x<<endl;//一つの変数を表示
#define OUTTWO(x,y) cout<<x<<" "<<y<<endl;//二つの変数を表示
#define OUTTHREE(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;//三つの変数を表示
typedef long long int64;
typedef pair<string,int> Psi;
typedef pair<int,int> Pii;
typedef pair<int,Pii> Ppii;
typedef struct{
  vector<Pii> to;
  int mins;
}Edge;
bool flag[105];
main(){
  int c,n,m,s,d;
  while(cin>>c>>n>>m>>s>>d,c||n||m||s||d){
    Edge edge[105];
    for(int i=1;i<=n;i++){
      edge[i].to.clear();
      flag[i]=true;
      edge[i].mins=INF;
    }
    REPI(i,0,m){
      int from,to,cost;
      cin>>from>>to>>cost;
      edge[from].to.push_back(Pii(to,cost));
      edge[to].to.push_back(Pii(from,cost));
    }
    priority_queue<Ppii,vector<Ppii>,greater<Ppii> > que;//F=cost,S.F=now,S.S=ticket
    que.push(Ppii(0,Pii(s,c)));
    while(!que.empty()){
      Ppii now=que.top();
      que.pop();
      int nowc=now.F,nowp=now.S.F,nowt=now.S.S;
      //DEBUGTHREE(nowc,nowp,nowt);
      if(nowp==d){
	OUTONE(nowc);
	break;
      }
      Edge nowe=edge[nowp];
      flag[nowp]=false;
      int size=nowe.to.size();
      REPI(i,0,size){
	int nextp=nowe.to[i].F;
	//DEBUGTWO(nowe.to[i].F,nowe.to[i].S);
	if(flag[nextp]==true&&edge[nextp].mins>nowc+edge[nowp].to[i].S){
	  //cout<<"A"<<endl;
	  edge[nextp].mins=nowc+edge[nowp].to[i].S;
	  que.push(Ppii(nowc+edge[nowp].to[i].S,Pii(nextp,nowt)));
	}
	if(nowt>0&&flag[nextp]==true&&edge[nextp].mins>nowc+(edge[nowp].to[i].S/2)){
	  //cout<<"B"<<endl;
	  edge[nextp].mins=nowc+(edge[nowp].to[i].S);
	  que.push(Ppii(nowc+(edge[nowp].to[i].S/2),Pii(nextp,nowt-1)));
	}
      }
    }
  }
}

C++: /**
 * 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;
}