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
}

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)
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				heap.Push(&pq, next)
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					heap.Push(&pq, next)
				}
			}
		}
	}
}

C++: #include<iostream>
#include<queue>
#include<vector>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)
#define INF 1000000000

struct edge {int cost, to; };

typedef pair<int, pair<int, int> > P; // cost, vertex, chicket
typedef pair<int, int> Pint; //

int c, n, m, s, d;
int dist[110][15];

int main() {
    while(true) {
        cin >> c >> n >> m >> s >> d;
        if (n==0) break;

        vector<edge> g[110];
        REP(i, m) {
            int a, b, f;
            cin >> a >> b >> f;
            
            edge e;
            e.to = b-1;
            e.cost = f;
            g[a-1].push_back(e);
            
            edge e2;
            e2.to = a-1;
            e2.cost = f;
            g[b-1].push_back(e2);
        }

        REP(i, n) {
            REP(j, c+1) {
                dist[i][j] = INF;
            }
        }
        dist[s-1][c] = 0;

        P p=pair<int, Pint>(0, Pint(s-1, c));
        priority_queue<P, vector<P>, greater<P> > que;
        que.push(p);

        while(!que.empty()) {
            P p = que.top();
            que.pop();

            int v = p.second.first;
            int ckt = p.second.second;
            if(dist[v][ckt] < p.first) continue;

            REP(i, g[v].size()) {
                int to = g[v][i].to;
                int cost = g[v][i].cost;
                // don't use chicket
                if (dist[to][ckt] > dist[v][ckt] + cost){
                    dist[to][ckt] = dist[v][ckt] + cost;
                    P p = pair<int, Pint>(dist[v][ckt] + cost, Pint(to, ckt));
                    que.push(p);
                }

                // use chicket
                if (ckt >= 1) {
                    if (dist[to][ckt-1] > dist[v][ckt] + cost/2){
                        dist[to][ckt-1] = dist[v][ckt] + cost/2;
                        P p = pair<int, Pint>(dist[v][ckt] + cost/2, Pint(to, ckt-1));
                        que.push(p);
                    }
                }
            }
        }
        
        int output = INF;
        REP(i, c+1) {
            output = min(output, dist[d-1][i]);
        }

        cout << output << endl;
    }
}

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;
}