Go: package main

import (
	"container/heap"
	"fmt"
	"runtime"
)

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)
					}
				}
			}
		}
		runtime.GC()
	}
}

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

const int INF = (int)1e9;

struct Edge {
  int src, dst, cost;
  Edge(int src_, int dst_, int cost_) : src(src_), dst(dst_), cost(cost_) { }
};

int main() {
  for(int C, N, M, S, T; cin >> C >> N >> M >> S >> T, C || N || M || S || T; ) {
    --S, --T;
    vector<Edge> G;
    for(int i = 0; i < M; ++i) {
      int a, b, f; cin >> a >> b >> f;
      --a, --b;
      G.emplace_back(a, b, f);
      G.emplace_back(b, a, f);
    }
    int D[N][C + 1];
    for(int i = 0; i < N; ++i)
      for(int j = 0; j <= C; ++j)
        D[i][j] = INF;
    D[S][C] = 0;
    while(true) {
      bool update = false;
      for(const Edge &e : G) {
        for(int j = 0; j <= C; ++j) {
          if(D[e.dst][j] > D[e.src][j] + e.cost) {
            D[e.dst][j] = D[e.src][j] + e.cost;
            update = true;
          }
          if(j > 0 && D[e.dst][j - 1] > D[e.src][j] + e.cost / 2) {
            D[e.dst][j - 1] = D[e.src][j] + e.cost / 2;
            update = true;
          }
        }
      }
      if(!update) break;
    }
    int ans = INF;
    for(int j = 0; j <= C; ++j) {
      ans = min(ans, D[T][j]);
    }
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <queue>
#define INF (1e9)
#define N 102
#define C 11
using namespace std;

typedef struct state {
  int cost,pos,ticket;
  state (int a,int b,int c): cost(a),pos(b),ticket(c){} 
  bool operator < (const state &s)const{
    return cost > s.cost;
  }
} state;

void dijkstra(int);
int c,n,d[N][C],M[N][N];
int main(){
  int m,s,ind,a,b,f;
  while(1){
    cin >> c >> n >> m >> s >> ind;
    if(c==0&&n==0&&m==0&&s==0&&ind==0) break;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	M[i][j]=INF;
    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      M[a][b]=M[b][a]=f;
    }
    dijkstra(s);
    cout << d[ind][c] << endl;
  }
  return 0;
}
void dijkstra(int s){
  priority_queue< state > q;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=c;j++)
      d[i][j]=INF;
  d[s][0]=0;
  q.push( (state){0,s,0} );
  while(!q.empty()){
    state r=q.top();
    q.pop();
    int cos=r.cost;
    pair<int,int> u=make_pair(r.pos,r.ticket);
    if(d[u.first][u.second]<cos) continue;
    for(int i=1;i<=n;i++){
      if(d[u.first][u.second]!=INF&&M[u.first][i]!=INF){
	if(d[i][u.second]>d[u.first][u.second]+M[u.first][i]){
	  d[i][u.second]=d[u.first][u.second]+M[u.first][i];
	  q.push((state){d[i][u.second],i,u.second});
	}
	if(u.second+1<=c&&d[i][u.second+1]>d[u.first][u.second]+M[u.first][i]/2){
	  d[i][u.second+1]=d[u.first][u.second]+M[u.first][i]/2;
	  q.push((state){d[i][u.second+1],i,u.second+1});
	}
      }
    }
  }
}

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

#define NONE -1

int c,n,m,s,d;
vector < vector <int> > P;
vector < vector <int> > E;
vector <int> R;
vector <bool> V;
int answer;

void solve( int t )
{
	if ( t == d )
	{
		sort( R.rbegin(), R.rend() );
		for ( int i = 0; i < c; i++ )
		{
			R[i] /= 2;
		}
		if ( answer == -1 )
			answer = accumulate( R.begin(), R.end(), 0 );
		else
			answer = min( answer, accumulate( R.begin(), R.end(), 0 ) );
	}
	else
	{
		V[t] = true;
		for ( vector <int>::iterator it = E[t].begin(); it != E[t].end(); it++ )
		{
			if ( V[*it] == false )
			{
				R.push_back( P[t][*it] );
				solve(*it);
				R.pop_back();
			}
		}
		V[t] = false;
	}
}

int main( void )
{
	while ( cin >> c >> n >> m >> s >> d && c && n && m && s && d )
	{
		s--;
		d--;
		P = vector < vector <int> >(n+1, vector <int>(n+1,NONE));
		E = vector < vector <int> >(n+1);
		for ( int i = 0; i < m; i++ )
		{
			int a, b, f;
			cin >> a >> b >> f;
			P[a-1][b-1] = f;
			P[b-1][a-1] = f;
			E[a-1].push_back( b-1 );
			E[b-1].push_back( a-1 );
		}

		R = vector <int>();
		V = vector <bool>(n+1,false);
		answer = -1;
		solve( s );
		cout << answer << endl;
	}

	return 0;
}

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

struct Data{
  int id;
  int cost;
  int ticket;
};
bool operator<(Data a, Data b){
  return a.cost!=b.cost?a.cost>b.cost:(a.ticket!=b.ticket?a.ticket<b.ticket:a.id>b.id);
}
struct Data2{
  int id;
  int ticket;
};
bool operator<(Data2 a, Data2 b){
  return a.id!=b.id?a.id>b.id:a.ticket<b.ticket;
}

#define NONE INT_MAX

int Dijkstra(vector< vector<int> >A,int start,int goal,int ticket)
{
  vector<int>cost(A.size(),NONE);
  priority_queue<Data>q;
  set<Data2>used;

  Data node={start,0,ticket};
  q.push(node);
  cost[start]=0;

  while(q.size()){
    node=q.top();q.pop();
    if(node.id==goal)return node.cost;
    Data2 t={node.id,node.ticket};
    if(used.count(t))continue;
    used.insert(t);
    for(int i=0;i<A[node.id].size();i++){
      if(A[node.id][i]==NONE)continue;
      if(node.ticket){
	if(cost[i]<=cost[node.id]+(A[node.id][i])/2)continue;
	Data next={i,cost[node.id]+(A[node.id][i])/2,node.ticket-1};
	cost[i]=next.cost;
	q.push(next);
      }else{
	if(cost[i]<=cost[node.id]+A[node.id][i])continue;
	Data next={i,cost[node.id]+A[node.id][i],node.ticket};
	cost[i]=next.cost;
	q.push(next);
      }
    }
  }
  return -1;
}

int main()
{
  int c,n,m,s,d;
  int a,b,f;
  while(cin>>c>>n>>m>>s>>d,c|n|m|s|d){
    s--;d--;
    vector< vector<int> >A(n,vector<int>(n,NONE));
    for(int i=0;i<m;i++){
      cin>>a>>b>>f;
      a--;b--;
      A[a][b]=A[b][a]=f;
    }
    cout<<Dijkstra(A,s,d,c)<<endl;
  }
}