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]int)
		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}] = now.Amount
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
					memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
						memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
						heap.Push(&pq, next)
					}
				}
			}
		}
		//runtime.GC()
	}
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#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(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
struct edge{int to,cost;};
int dp[100][11];
vector<edge> G[100];
int main(){
      int c,n,m,s,d;
      while(cin>>c>>n>>m>>s>>d&&(c||n||m||s||d)){
            s--;d--;
            REP(i,100)REP(j,11)dp[i][j]=INF;
            REP(i,100)G[i].clear();
            REP(i,m){
                  int x,y,z;
                  cin>>x>>y>>z;x--;y--;
                  G[x].PB((edge){y,z});
                  G[y].PB((edge){x,z});
            }
            dp[s][0]=0;
            queue<int> Q;
            Q.push(s);
            while(!Q.empty()){
                  int v=Q.front();Q.pop();
                  //cout<<v<<" "<<G[v].size()<<endl;
                  REP(i,G[v].size()){
                        bool f=false;
                        edge e=G[v][i];
                        int to=e.to;
                        REP(i,c+1){
                              //cout<<dp[v][i]+e.cost<<endl;;
                              if(dp[to][i]>dp[v][i]+e.cost){
                                    dp[to][i]=dp[v][i]+e.cost;
                                    f=true;
                              }
                        }
                        REP(i,c){
                              if(dp[to][i+1]>dp[v][i]+e.cost/2){
                                    dp[to][i+1]=dp[v][i]+e.cost/2;
                                    f=true;
                              }
                        }
                        if(f)Q.push(to);
                  }
            }
            int ans=INF;
            REP(i,c+1)ans=min(ans,dp[d][i]);
            cout<<ans<<endl;
      }
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

struct Node
{
	int num, cost, tic;

	Node( int n, int c, int t ) : num( n ), cost( c ), tic( t )
	{
		return;
	}

	bool operator > ( const Node &a ) const
	{
		return cost > a.cost;
	}
};

struct Edge
{
	int to, cost;

	Edge( int t, int c ) : to( t ), cost( c )
	{
		return;
	}
};

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	while ( true )
	{
		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;

		if ( !( c | n | m | s | d ) )
		{
			break;
		}

		s--;
		d--;

		vector< vector< Edge > > G( n, vector< Edge >() );

		REP( i, 0, m )
		{
			int a, b, f;
			cin >> a >> b >> f;

			a--;
			b--;

			G[a].PB( Edge( b, f ) );
			G[b].PB( Edge( a, f ) );
		}

		VVI dist( n, VI( c + 1, INT_MAX ) );

		priority_queue< Node, vector< Node >, greater< Node > > que;
		que.push( Node( s, 0, 0 ) );

		while ( !que.empty() )
		{
			Node cur = que.top();
			que.pop();

			if ( c < cur.tic ||
				 dist[ cur.num ][ cur.tic ] < cur.cost )
			{
				continue;
			}

			dist[ cur.num ][ cur.tic ] = cur.cost;

			REP( i, 0, G[ cur.num ].size() )
			{
				que.push( Node( G[ cur.num ][i].to, cur.cost + G[ cur.num ][i].cost, cur.tic ) );
				que.push( Node( G[ cur.num ][i].to, cur.cost + G[ cur.num ][i].cost / 2, cur.tic + 1 ) );
			}
		}

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

	return 0;
}