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, 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]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 Edge {                                                                                                   
    int to, cost;                                                                                               
};                                                                                                              
                                                                                                                
struct Node {                                                                                                   
    int ticket;                                                                                                 
    int cost;                                                                                                   
    vector<Edge> route;                                                                                         
                                                                                                                
    bool operator<(const Node &r) const {                                                                       
        return cost < r.cost;                                                                                   
    }                                                                                                           
};                                                                                                              
                                                                                                                
int main() {                                                                                                    
                                                                                                                
    int c, n, m, s, d;                                                                                          
                                                                                                                
    while(cin >> c >> n >> m >> s >> d, c | n | m | s | d) {                                                    
                                                                                                                
        Node node[n];                                                                                           
        int cost[n][c + 1];                                                                                     
        priority_queue<Node, vector<Node> > q;                                                                  
                                                                                                                
        for(int i = 0, a, b, f; i < m; ++i) {                                                                   
            cin >> a >> b >> f;                                                                                 
            node[a - 1].route.push_back((Edge){b - 1, f});                                                      
            node[b - 1].route.push_back((Edge){a - 1, f});                                                      
        }                                                                                                       
                                                                                                                
        for(int i = 0; i < n; ++i) {                                                                            
            for(int j = 0; j < c + 1; ++j) {                                                                    
                cost[i][j] = 1 << 24;                                                                           
            }                                                                                                   
        }                                                                                                       
                                                                                                                
        for(int i = 0; i < c + 1; ++i) {                                                                        
            cost[s - 1][i] = 0;                                                                                 
        }                                                                                                       
                                                                                                                
        node[s - 1].ticket = c;                                                                                 
        node[s - 1].cost = 0;                                                                                   
                                                                                                                
        q.push(node[s - 1]);                                                                                    
                                                                                                                
        while(!q.empty()) {                                                                                     
                                                                                                                
            Node now = q.top(); q.pop();                                                                        
                                                                                                                
            for(int i = 0; i < now.route.size(); ++i) {                                                         
                                                                                                                
                Node next = node[now.route[i].to];                                                              
                                                                                                                
                if(now.cost + now.route[i].cost < cost[now.route[i].to][now.ticket]) {                          
                    next.cost = cost[now.route[i].to][now.ticket] = now.cost + now.route[i].cost;               
                    next.ticket = now.ticket;                                                                   
                    q.push(next);                                                                               
                }                                                                                               
                                                                                                                
                if(now.ticket > 0 && now.cost + now.route[i].cost / 2 < cost[now.route[i].to][now.ticket - 1]) {
                    next.cost = cost[now.route[i].to][now.ticket - 1] = now.cost + now.route[i].cost / 2;       
                    next.ticket = now.ticket - 1;                                                               
                    q.push(next);                                                                               
                }                                                                                               
                                                                                                                
            }                                                                                                   
                                                                                                                
        }                                                                                                       
                                                                                                                
        int min_cost = 1 << 24;                                                                                 
        for(int i = 0; i < c + 1; ++i) {                                                                        
            min_cost = min(min_cost, cost[d - 1][i]);                                                           
        }                                                                                                       
                                                                                                                
        cout << min_cost << endl;                                                                               
                                                                                                                
    }                                                                                                           
                                                                                                                
}