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 <algorithm>

#define MAX 1000000000
#define Debug(X) debug( __LINE__, X )
template<class T>
void debug( int line, T dbg ){
	std::cout << line << ": " << dbg << std::endl;
}

class State{
public:
	int p, s, c;
	State():p(0), s(0), c(0){}
	State(int P, int S, int C):p(P), s(S), c(C){}
	bool operator < (const State &s) const{
		return c > s.c;
	}
};

int c, n, m, s, d;
int route[101][101];
std::priority_queue<State> que;
bool used[101];


int main(){
	while( std::cin >> c >> n >> m >> s >> d, c * n * m * s * d ){
		for( int i = 0; i < 101 * 101; ++i )
			route[i / 101][i % 101] = MAX;
		
		memset( used, 0, sizeof( used ) );
		que = std::priority_queue<State>();

		int tmp[3];
		while( m-- ){
			int cnt = 3;
			while( cnt-- ) std::cin >> tmp[2 - cnt];

			route[tmp[0]][tmp[1]] = tmp[2];
			route[tmp[1]][tmp[0]] = tmp[2];
		}

		que.push(State( c, s, 0 ));

		while( true ){
			State data = que.top(); que.pop();

			if( used[data.s] )continue;
			used[data.s] = 1;

			if( data.s == d ){
				std::cout << data.c << std::endl;
				break;
			}

			for( int i = 1; i <= n; ++i ){
				if( i == data.s || route[data.s][i] == MAX )continue;

				if( data.p > 0 )
					que.push( State( data.p - 1, i, data.c + route[data.s][i] / 2 ) );

				que.push( State( data.p, i, data.c + route[data.s][i] ) );				
			}

		}

	}
}

C++: #include<iostream>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
#define MAX 100
#define INFTY (1<<21)

int G[MAX][MAX], c, n, s, d;

int dijkstra(){
    int D[MAX][11];
    bool V[MAX][11];
    rep(i, n) rep(k, c+1) { D[i][k] = INFTY; V[i][k] = false; }

    D[s][c] = 0;

    while(1){
	int u, w, minv = INFTY;
	rep(i, n) rep(k, c+1){
	    if ( !V[i][k] && minv > D[i][k] ){ 
		minv = D[i][k]; u = i; w = k; 
	    }
	}
	if ( minv == INFTY ) break;
	V[u][w] = true;
	rep(v, n){
	    if ( G[u][v] == INFTY ) continue;
	    D[v][w] = min(D[v][w], D[u][w] + G[u][v]);
	    if ( w ) D[v][w-1] = min(D[v][w-1], D[u][w] + G[u][v]/2);
	}
    }
    int minv = INFTY;
    rep(k, c+1) minv = min(minv, D[d][k]);
    return minv;
}

main(){
    int m, a, b, f;
    while( cin >> c >> n >> m >> s >> d && c){
	s--; d--;
	rep(i, n) rep(j, n) G[i][j] = INFTY;
	rep(i, m){
	    cin >> a >> b >> f; a--; b--;
	    G[a][b] = G[b][a] = f;
	}
	cout << dijkstra() << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct edge {
  int from, to, cost;
  edge(int f = -1, int t = -1, int c = 0) : from(f), to(t), cost(c) {}
};

int c, n, m, s, d;
int dis[110][11];
vector<edge> g[110];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> c >> n >> m >> s >> d, c) {
    s--, d--;
    for (int i = 0; i < n; i++) g[i].clear();
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      a--, b--;
      g[a].emplace_back(a, b, f);
      g[b].emplace_back(b, a, f);
    }
    fill_n((int*)dis, 110 * 11, 1 << 30);
    dis[s][c] = 0;
    using P = tuple<int, int, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0, s, c);
    while (!que.empty()) {
      P u = que.top(); que.pop();
      int dist, curr, tic;
      tie(dist, curr, tic) = u;
      if (dist > dis[curr][tic]) continue;
      for (auto e : g[curr]) {
        int next = e.to;
        if (dis[next][tic] > dis[curr][tic] + e.cost) {
          dis[next][tic] = dis[curr][tic] + e.cost;
          que.emplace(dis[next][tic], next, tic);
        }
        if (tic > 0 && dis[next][tic - 1] > dis[curr][tic] + e.cost / 2) {
          dis[next][tic - 1] = dis[curr][tic] + e.cost / 2;
          que.emplace(dis[next][tic - 1], next, tic - 1);
        }
      }
    }
    int ans = 1 << 30;
    for (int i = 0; i <= c; i++) {
      ans = min(ans, dis[d][i]);
    }
    cout << ans << endl;
  }

  return 0;
}