Go: package main

import (
	"container/heap"
	"fmt"
	"runtime"
)

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, n)
		}
		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, m)
		start := Node{NowPosition: s, DiscountTicketTCount: c, Amount: 0}
		heap.Push(&pq, &start)
		memo := make(map[Memo]int)
		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}] = now.Amount
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
					memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
						memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
						heap.Push(&pq, next)
					}
				}
			}
		}
		runtime.GC()
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  using P = pair<int,int>;
  int c,n,m,s,t;
  while(cin>>c>>n>>m>>s>>t, c|n|m){
    s--;t--;
    vector<vector<P>> vec(n);
    rep(i,m){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      vec[a].pb(mp(f,b));
      vec[b].pb(mp(f,a));
    }

    vector<vector<int>> d(n,vector<int>(c+1,INF));
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push(mp(0,s*(c+1)));
    d[s][c] = 0;
    while(!pq.empty()){
      auto p = pq.top(); pq.pop();
      int v = p.se/(c+1);
      int k = p.se%(c+1);
      if(d[v][k] < p.fi) continue;

      auto go = [&](int nv, int nk, int dist){
        if(d[nv][nk] > dist){
          pq.push(mp(dist, nv*(c+1)+nk));
          d[nv][nk] = dist;
        }
      };

      for(auto to : vec[v]){
        go(to.se, k, p.fi + to.fi);
        if(k<c) go(to.se, k+1, p.fi + to.fi/2);
      }
    }

    cout << *min_element(all(d[t])) << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>

const int INF = 1 << 24;
int ticket, V, E, start, goal;
//d[i][j]: i枚使ったんだよー
int d[11][101], used[11][101], cost[101][101];

int dijkstra(int s){
	for(int i=0;i<11;i++){
		std::fill(d[i], d[i]+101, INF);
		std::fill(used[i], used[i]+101, 0);
	}

	d[0][s] = 0;

	while(true){
		int u = -1, v;
		for(int i=0;i<=ticket;i++){
			for(int j=1;j<=V;j++){
				if(!used[i][j] && (u == -1 || d[i][j] < d[u][v])){
					u = i;
					v = j;
				}
			}
		}

		if(u == -1)break;
		used[u][v] = 1;

		for(int j=1;j<=V;j++){
			d[u][j] = std::min(d[u][j], d[u][v] + cost[v][j]);
			if(u+1 <= ticket){
				d[u+1][j] = std::min(d[u+1][j], d[u][v] + cost[v][j] / 2);
			}
		}
	}
	
}

int main(){
	while(std::cin >> ticket >> V >> E >> start >> goal, V){
		for(int i=1;i<=100;i++){
			for(int j=1;j<=100;j++){
				cost[i][j] = INF;
			}
		}
		for(int i=0;i<E;i++){
			int a, b, f;
			std::cin >> a >> b >> f;
			cost[a][b] = cost[b][a] = f;
		}
		dijkstra(start);
		int res = INF;
		for(int i=0;i<=ticket;i++){
			res = std::min(res, d[i][goal]);
		}
		std::cout << res << std::endl;
	}
}

C++: #include<iostream>
#include<queue>
#include<string.h>
using namespace std;

const int INF = 1<<30;

struct Node{
  int use,to,weight;
  Node() {;}
  Node(int use,int to,int weight) : use(use), to(to), weight(weight) {;}
};
bool operator<(const Node &e,const Node &f) {
  return e.weight > f.weight;
}

int dist[110][110];
bool visit[110];
int dist2[110][110];

int main() {
  int c,n,m,s,d,a,b,f;
    while(cin>>c>>n>>m>>s>>d, c|n|m|s|d) {
      s--,d--;

      for(int i=0; i<110; ++i) {
	for(int j=0; j<110; ++j) {
	  dist[i][j] = INF;
	}
	visit[i] = false;
      }

      for(int i=0; i<110; ++i)
	for(int j=0; j<110; ++j)
	  dist2[i][j] = INF;

      for(int i=0; i<m; ++i) {
	cin>>a>>b>>f;
	a--,b--;
	dist[a][b] = f;
      }

      priority_queue<Node> Q;
      Q.push(Node(0,s,0));
      visit[s] = true;
      while(!Q.empty()) {
	Node now = Q.top(); Q.pop();

	if(now.to == d) {
	  cout<<now.weight<<endl;
	  break;
	}

	visit[now.to] = true;
	for(int i=0; i<n; ++i) {
	  if(!visit[i] && dist[now.to][i] != INF) {
	    if(dist2[now.use+1][i]
	       > now.weight + dist[now.to][i]/2 && now.use < c) {
	      dist2[now.use+1][i] = now.weight + dist[now.to][i]/2;
	      Q.push(Node(now.use+1, i, dist2[now.use+1][i]));
	    }
	    if(dist2[now.use][i]
	       > now.weight + dist[now.to][i]) {
	      dist2[now.use][i] = now.weight + dist[now.to][i];
	      Q.push(Node(now.use, i, dist2[now.use][i]));
	    }
	  }
	}
      }

/*
      for(int i=0; i<=c; ++i) {
	cout<<dist2[i][d]<<" : "<<i<<endl;
      }
*/
    }
}