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;
struct NODE{
  int to,cost,tick;
  NODE(int to,int cost,int tick) : to(to),cost(cost),tick(tick){}
  NODE(){}
  bool operator < (const NODE &a)const{
    return cost > a.cost;
  }
};
int main(){
  int c,n,m,s,d,a,b,f;
  while(cin>>c>>n>>m>>s>>d&&c&&n&&m&&s&&d){
    vector<NODE> edge[101];
    
    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      edge[a].push_back(NODE(b,f,-1));
      edge[b].push_back(NODE(a,f,-1));
    }
    bool done[101][20] = {};
    priority_queue<NODE> Q;
    Q.push(NODE(s,0,c));
    while(!Q.empty()){
      NODE q = Q.top();Q.pop();
      if(done[q.to][q.tick] == true)continue;
      done[q.to][q.tick] = true;
      if(q.to == d){
	cout << q.cost << endl;
	break;
      }
      for(int i=0;i<edge[q.to].size();i++){
	Q.push(NODE(edge[q.to][i].to,q.cost + edge[q.to][i].cost,q.tick));
	if(q.tick){
	  Q.push(NODE(edge[q.to][i].to,q.cost + (edge[q.to][i].cost/2),q.tick-1));
	}
      }
    }
  }
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

const int MAX_V = 101;
const int INF = 1e+8;

// 頂点は(ノード番号,割引券の数)の組
typedef pair<int,int> P;
// 状態は(コスト,頂点)の組
typedef pair<int,P> State;

struct edge{
	int to, cost;
	edge(int v, int cost_){
		to = v;
		cost = cost_;
	}
};

// 頂点数
int V;
// G[u][i] = ノード u に接続している i 番目の edge が返ってくる
vector<edge> G[MAX_V];

// 初期化
void init(int n){
	V = n;
	for(int i = 0 ; i < MAX_V ; i++ ){
		G[i].clear();
	}
}


// ノード番号 s を始点, 割引券の枚数を c としたダイクストラ法
int dijkstra(int s, int c, int g){
	// greater<State> を指定することで コスト が小さい順に取り出せる
	priority_queue<State, vector<State>, greater<State> > q;
	
	// d[c][v] := 割引券 c 枚でノード番号 v にたどり着く最小コスト
	int d[11][101];
	for(int i=0 ; i < 11 ; i++ ){
		for(int j=0 ; j < 101 ; j++ ){
			d[i][j] = INF;
		}
	}
	
	d[c][s] = 0;
	State start( 0 , P(s,c) );
	q.push( start );
	
	int result = INF;
	while( !q.empty() ){
		int now_cost = q.top().first;
		int v = q.top().second.first;
		int c =  q.top().second.second;
		q.pop();
		
		if( v == g ){
			result = now_cost;
			break;
		}
		
		if( d[c][v] < now_cost ) continue;
		
		for(int i=0 ; i < G[v].size() ; i++ ){
			edge e = G[v][i];
			
			int next_cost = d[c][v] + e.cost;
			if( next_cost < d[c][e.to] ){
				d[c][e.to] = next_cost;
				State next( next_cost , P(e.to,c) );
				q.push( next );
			}
			if( c > 0 ){
				next_cost = d[c][v] + e.cost/2 ;
				if( next_cost < d[c-1][e.to] ){
					d[c-1][e.to] = next_cost;
					State next( next_cost , P(e.to,c-1) );
					q.push( next );
				}
			}
		}
	}
	return result;
}

// 重み cost の辺 (u,v) の追加
void add_edge(int u, int v, int cost){
	edge e( v , cost );
	G[u].push_back( e );
	e.to = u;
	G[v].push_back( e );
}


int main(){
	int c,n,m,s,g;
	while( cin >> c >> n >> m >> s >> g, c || n || m || s || g ){
		init(n);
		s--; g--;
		for(int i=0 ; i < m ; i++ ){
			int u, v, cost;
			cin >> u >> v >> cost;
			u--; v--;
			add_edge(u,v,cost);
		}
		int ans = dijkstra( s , c , g );
		cout << ans << endl;
	}
}