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 <iostream>
#include <vector>
#include <queue>

using namespace std;

struct node {
	int to, cost, ticket;

	node(int to, int cost) : to(to), cost(cost) { this -> ticket = 0; }
	node(int to, int cost, int ticket) : to(to), cost(cost), ticket(ticket) { }
	node() { this -> to = this -> cost = this -> ticket = 0; }
};

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

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, c || n || m || s || d) {
		--s, --d;

		vector< vector<node> > v(n);
		for (int i = 0; i < m; ++i) {
			int a, b, f; cin >> a >> b >> f;
			--a, --b;
			v[a].push_back( node(b, f) );
			v[b].push_back( node(a, f) );
		}

		int rest = c;
		vector< vector<int> > cost(n, vector<int>(c+1, -1));
		vector<bool> used(n, -1);
		priority_queue< node, vector<node>, greater<node> > que; que.push( node(s, 0, c) );
		while ( !que.empty() ) {
			node next = que.top(); que.pop();

			if (cost[next.to][next.ticket] >= 0) continue;
			cost[next.to][next.ticket] = next.cost;

			rest = min(rest, next.ticket);

			for (int i = 0; i < v[next.to].size(); ++i) {
				que.push( node(v[next.to][i].to, next.cost + v[next.to][i].cost, next.ticket) );
				if (next.ticket) que.push( node(v[next.to][i].to, next.cost + v[next.to][i].cost/2, next.ticket-1) );
			}
		}

		cout << cost[d][0] << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>

#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) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v));
#define MP make_pair
#define X first
#define Y second

using namespace std;

const double EPS = 1e-8;

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

template<class T> inline T sq(T a){return a*a;}
template<class T> T gcd(T m, T n){return n?gcd(n, m%n):m;}

int dp[101][11];

vector<P> G[101];

struct state{
	int p, c, t;
	state(int p, int c, int t):p(p), c(c), t(t){}
	bool operator<(const state &r) const {
		return c > r.c;
	}
};

int main(){
	int c, n, m, s, d;
	while(cin >> c >> n >> m >> s >> d, c|n|m|s|d){
		rep(i, 101) G[i].clear();
		s--, d--;
		rep(i, m){
			int a, b, f;
			cin >> a >> b >> f;
			a--, b--;
			G[a].push_back(MP(b, f));
			G[b].push_back(MP(a, f));
		}
		rep(i, 101) rep(j, 11) dp[i][j] = 1<<29;

		priority_queue<state> q;
		q.push(state(s, 0, c));
		int ans = -1;
		while(!q.empty()){
			state st = q.top();
			q.pop();

			if(dp[st.p][st.t] < st.c) continue;
			if(st.p == d) break;

			rep(i, G[st.p].size()){
				state next = st;
				next.p = G[st.p][i].first;
				next.c += G[st.p][i].second;
				if(next.c < dp[next.p][next.t]){
					dp[next.p][next.t] = next.c;
					q.push(next);
				}
				if(next.t > 0){
					next.c -= G[st.p][i].second/2;
					next.t--;
					if(next.c < dp[next.p][next.t]){
						dp[next.p][next.t] = next.c;
						q.push(next);
					}
				}
			}
		}

		cout << *min_element(dp[d], dp[d]+11) << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<map>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair< long long ,long long > P;
typedef pair< long long , P > road;
main(){
  while(1){
    long long c,n,m,s,d;
    long long a,b,f;
    vector< P > bus[120];
    long long min_cost[120];
    queue< road > que;
    road r;
    P p;
    cin>>c>>n>>m>>s>>d;//c waribiki n mati m rosen s start d goal
    if(c==0&&n==0&&m==0&&s==0&&d==0)break;
    for(int i=1;i<=n;i++){
      min_cost[i]=1<<21;
    }
    for(int i=0;i<m;i++){
      cin>>a>>b>>f;
      p.first=b;
      p.second=f;
      bus[a].push_back(p);
      p.first=a;
      p.second=f;
      bus[b].push_back(p);
    }
    r.first=c;
    r.second.first=s;
    r.second.second=0;
    que.push(r);
    while(!que.empty()){
      road now=que.front();
      int size=bus[now.second.first].size();
      for(int i=0;i<size;i++){
	if(bus[now.second.first][i].second+now.second.second<min_cost[bus[now.second.first][i].first]){
	  min_cost[bus[now.second.first][i].first]=bus[now.second.first][i].second+now.second.second;
	  r.first=now.first;
	  r.second.first=bus[now.second.first][i].first;
	  r.second.second=bus[now.second.first][i].second+now.second.second;
	  que.push(r);
	}
	if(now.first!=0&&bus[now.second.first][i].second/2+now.second.second<min_cost[bus[now.second.first][i].first]){
	  min_cost[bus[now.second.first][i].first]=bus[now.second.first][i].second/2+now.second.second;
	  r.first=now.first-1;
	  r.second.first=bus[now.second.first][i].first;
	  r.second.second=bus[now.second.first][i].second/2+now.second.second;
	  que.push(r); 
	}
      }  
      que.pop();
    }
    while(!que.empty()){
      que.pop();
    }
    cout<<min_cost[d]<<endl;
  }
}