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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 10000;


class V{
public:
	int total;
	int ticket;
	int to;
};
bool operator>(const V &lh, const V &rh){
	return (lh.total > rh.total);
}


int main(){
	while(1){

		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if(!(c+n+m+s+d))break;
		n++;
		vector<vector<int> > fare(n, vector<int>(n, INF));
		rep(i, m){
			int a, b, f;
			cin >> a >> b >> f;
			fare[a][b] = fare[b][a] = f;
		}

		vector<vector<int> > done(c+1, vector<int>(n, 0));	// 確定済みか
		vector<vector<int> > best(c+1, vector<int>(n, INF));	// 最短

		V start;
		start.total = 0;
		start.ticket = 0;
		start.to = s;

		priority_queue<V, vector<V>, greater<V> > q;
		q.push(start);

		while(!q.empty()){
			V p = q.top();
			q.pop();

			if(done[p.ticket][p.to] != 0) continue;
			done[p.ticket][p.to] = 1;
			best[p.ticket][p.to] = p.total;

			rep(i, n){
				if(fare[p.to][i] == INF ) continue;
				V next;
				if(!done[p.ticket][i]){
					next.total = p.total + fare[p.to][i];
					next.ticket = p.ticket;
					next.to = i;
					q.push(next);
				}
				if(p.ticket < c){
					if(!done[p.ticket+1][i]){
						next.total = p.total + fare[p.to][i]/2;
						next.ticket = p.ticket+1;
						next.to = i;
						q.push(next);
					}
				}
			}
		}
		//rep(i, c+1){
		//	rep(j, n){
		//		printf("%5d", best[i][j]);
		//	}
		//	cout << endl;
		//}

		cout << best[c][d] << endl;
	}

	return 0;
}

C++: typedef pair<int, int> pi; // ?????????????????? ?????¨??????
typedef pair<int, pi>P; // ????????? pi

struct edge{ int to, cost; };

int C, V, E, S, D;
int d[128][16];
vector<vector<edge> >G(128);

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> >q;
  rep(i, V) rep(j, C+1) d[i][j] = INF;
  d[s][C] = 0;
  q.push(MP(0, MP(C, s)));

  while(!q.empty()){
    P p = q.top(); q.pop();
    int v = p.S.S;
    int c = p.S.F;

    rep(i, G[v].size()){
      edge e = G[v][i];
      if(d[e.to][c] > d[v][c] + e.cost){
    d[e.to][c] = d[v][c] + e.cost;
    q.push(MP(d[e.to][c], MP(c, e.to)));
      }

      if( c > 0 && d[e.to][c-1] > d[v][c] + e.cost/2){
      d[e.to][c-1] = d[v][c] + e.cost/2;
      q.push(MP(d[e.to][c-1], MP(c-1, e.to)));
      }
    }
  }
}

int main(){
  while(scanf("%d%d%d%d%d", &C, &V, &E, &S, &D) && C+V+E+S+D){
    S--; D--;
    rep(i, 128){
      G[i].clear();
    }

    rep(i, E){
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c); a--; b--;
     edge e;
      e.to = a; e.cost = c;
      G[b].PB(e);
      e.to = b;
      G[a].PB(e);
    }

    dijkstra(S);

    int res = INF;
    rep(i, C+1) res = min(res, d[D][i]);
    printf("%d\n", res);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int c,n,m,s,d;
int rosen[101][101] = {-1};
int saiki(int p,vector<int> st,vector<bool> &u){
    int ans = INF;
    if(p == d){
	sort(RALL(st));
	int tc = min(c,(int)(st.size()));
	REP(i,tc){
	    st[i] /= 2;
	}
	int sum = 0;
	REP(i,st.size()){
	    sum += st[i];
	}
	return sum;
    }
    FOR(i,1,n+1){
	if(!u[i] && rosen[p][i] > 0){
	    vector<int> temp = st;
	    vector<bool> utemp = u;
	    temp.PB(rosen[p][i]);
	    utemp[i] = true;
	    ans = min(ans,saiki(i,temp,utemp));
	}
    }
    return ans;
}

int main(){
    while(true){
	cin >> c >> n >> m >> s >> d;
	if(c==0&&n==0&&m==0&&s==0&&d==0) break;
	memset(rosen,-1,sizeof(rosen));
	REP(i,m){
	    int a,b,f;
	    cin >> a >> b >> f;
	    rosen[a][b] = f;
	    rosen[b][a] = f;
	}
	vector<bool>  used(n+1,false);
	vector<int> nanika;
	used[s] = true;
	cout << saiki(s, nanika ,used) << endl;
    }
    return 0;
}

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

struct NODE{
	int to,cost,ticket;
	NODE(int to,int cost,int ticket) : to(to) , cost(cost) , ticket(ticket) {}
	NODE(){}
};


bool operator < (const NODE &a,const NODE &b){
	return a.cost > b.cost;
}

int main(){
	int c,n,m,s,d;
	while(cin >> c >> n >> m >> s >> d && n){
		s--,d--;
		vector<NODE> e[100];
		for(int i = 0 ; i < m ; i++){
			int a,b,f;
			cin >> a >> b >> f;
			a--,b--;
			e[a].push_back(NODE(b,f,-1));
			e[b].push_back(NODE(a,f,-1));
		}
		int done[110][15] = {};
		priority_queue<NODE> Q;
		Q.push(NODE(s,0,c));
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if( done[q.to][q.ticket]++ ) continue;
			else done[q.to][q.ticket] = true;
			if( q.to == d){
				cout << q.cost << endl;
				break;
			}
			for(int i = 0 ; i < e[q.to].size() ; i++){
				Q.push(NODE(e[q.to][i].to,q.cost+e[q.to][i].cost,q.ticket));
				if( q.ticket ) Q.push(NODE(e[q.to][i].to,q.cost+e[q.to][i].cost/2,q.ticket-1));
			}
		}
	}
}