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 <iostream>
#include <vector>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
using namespace std;
typedef pair<int, int> edge;
struct state{
  int cost, coupon, station;
  state(int cost_, int coupon_, int station_):cost(cost_), coupon(coupon_), station(station_){}
  bool operator< (const state &s) const{
    if(cost == s.cost){
      return coupon > s.coupon;
    }
    return cost > s.cost;
  }
};
int djikstra(vector<vector<edge> > graph, int start, int goal, int coupon){
  priority_queue<state> pq;
  pq.push(state(0, coupon, start));
  bool visited[coupon+1][graph.size()];
  fill_n((bool*)visited, (coupon+1) * graph.size(), false);
  return 0;
  while(!pq.empty()){
    state cur = pq.top(); pq.pop();
    if(visited[cur.coupon][cur.station]){
      continue;
    }
    if(cur.station == goal){
      return cur.cost;
    }
    visited[cur.coupon][cur.station] = true;
    for(int i = 0; i < graph[cur.station].size(); ++i){
      int to = graph[cur.station][i].first;
      int c = graph[cur.station][i].second;
      if(cur.coupon > 0){
        pq.push(state(cur.cost+c/2, cur.coupon-1, to));
      }
      pq.push(state(cur.cost+c, cur.coupon, to));
    }
  }
  //assert(false);
  return -1;
}
int main(){
  int c, n, m, s, d;
  while(true){    
    cin >> c >> n >> m >> s >> d;
    if((c|n|m|s|d) == 0){
      break;
    }
    vector<vector<edge> > graph(n+1, vector<edge>());
    for(int i = 0; i < m; ++i){
      int a, b, f;
      cin >> a >> b >> f;
      graph[a].push_back(make_pair(b, f));
      graph[b].push_back(make_pair(a, f));
    }
    cout << djikstra(graph, s, d, c) << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 120
#define INF 1e9
 
struct Edge {
    int to, cost;
    Edge(int t, int c) : to(t), cost(c) {}
};
 
struct State {
    int cost, v, tic;
    State(int c, int v, int t) : cost(c), v(v), tic(t) {}
    bool operator < (const State &s) const {
	return cost > s.cost;
    }
};
 
int C, V, E, src, dst;
vector<Edge> G[MAX];
 
int dijkstra()
{
    priority_queue<State> Q;
    Q.push(State(0, src, C));
    int dist[MAX][11];
    fill(dist[0], dist[0]+MAX*11, INF);
    dist[src][C] = 0;
   
    while (!Q.empty()) {
	State s = Q.top(); Q.pop();
	int v = s.v,t = s.tic;
	if (dist[v][t] < s.cost) continue;
	if (v == dst) return dist[v][t];
     
	for (int i = 0; i < (int)G[v].size(); i++) {
	    Edge e = G[v][i];
	    if (dist[v][t] + e.cost < dist[e.to][t]) {
		dist[e.to][t] = dist[v][t] + e.cost;
		Q.push(State(dist[e.to][t], e.to, t));
	    }
	    if (t > 0) {
		if (dist[v][t] + e.cost/2 < dist[e.to][t-1]) {
		    dist[e.to][t-1] = dist[v][t] + e.cost/2;
		    Q.push(State(dist[e.to][t-1], e.to, t-1));
		}
	    }
	}
    }
}
 
int main()
{
    while (cin >> C >> V >> E >> src >> dst, C) {
	src--; dst--;
	for (int i = 0; i < V; i++) {
	    G[i].clear();
	}
	for (int i = 0; i < E; i++) {
	    int a,b,c;
	    cin >> a >> b >> c; a--; b--;
	    G[a].push_back(Edge(b, c));
	    G[b].push_back(Edge(a, c));
	}
	cout << dijkstra() << endl;
    }
    return 0;
}