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>
#define INF (1e9)
#define N 101
#define C 11
using namespace std;
void dijkstra(int);
int M[N][N],d[N][C],c,n;
typedef struct data{
  int cost,pos,ticket;
  bool operator<(const data & right)const{
    return cost > right.cost;
  }
} data;
int main(){
  int m,s,id,a,b,f;
  while(1){
    cin >> c >> n >> m >> s >> id;
    if(c==0&&n==0&&m==0&&s==0&&id==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);
    int mincost=INF;
    for(int i=0;i<=c;i++){
      mincost=min(mincost,d[id][i]);
    }
    cout << mincost << endl;
  }
  return 0;
}
void dijkstra(int s){
  priority_queue<data> q;
  for(int i=1;i<=n;i++)
    for(int j=0;j<=c;j++)
      d[i][j]=INF;
  d[s][0]=0;
  q.push((data){0,s,0});
  while(!q.empty()){
    data t=q.top();
    q.pop();
    int cost=t.cost,pos=t.pos,ticket=t.ticket;
    if(d[pos][ticket]>cost) continue;
    for(int i=1;i<=n;i++){
      if(d[i][ticket]>d[pos][ticket]+M[pos][i]){
	d[i][ticket]=d[pos][ticket]+M[pos][i];
	q.push((data){d[i][ticket],i,ticket});
      }
      if(ticket==c) continue;
      if(d[i][ticket+1]>d[pos][ticket]+M[pos][i]/2){
	d[i][ticket+1]=d[pos][ticket]+M[pos][i]/2;
	q.push((data){d[i][ticket+1],i,ticket+1});
      }
    }
  }
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
using CostType = long long int;
const CostType INF = 1LL << 60;

struct Elem {
  CostType pos, tic, cost;
  Elem(CostType a, CostType b, CostType c) : pos(a), tic(b), cost(c) {}
  bool operator<(const Elem &e) const {
    return cost > e.cost;
  }
};

int solve() {
  CostType rec[110][15];
  vector< pair<int, int> > G[110];
  
  int C, N, M, S, D; cin >> C >> N >> M >> S >> D;
  if(C == 0) return 1;
  
  for(int i=0; i<N; i++) G[i].clear();
  
  for(int i=0; i<M; i++) {
    CostType u, v, cost; cin >> u >> v >> cost;
    u--; v--;
    G[u].emplace_back(v, cost);
    G[v].emplace_back(u, cost);
  }

  S--; D--;
  priority_queue<Elem> que;
  fill(rec[0], rec[N+1], INF);
  rec[S][0] = 0;
  que.emplace(S, 0, 0);

  while(que.size()) {
    auto cur = que.top(); que.pop();
    if(cur.cost > rec[cur.pos][cur.tic]) continue;
    CostType mon = cur.cost;
    for(auto e : G[cur.pos]) {
      CostType u = cur.pos, v = e.first, c = e.second;
      if(cur.tic + 1 <= C) {
        int nt = cur.tic + 1, nc = mon + c / 2;
        if(rec[v][nt] > nc) {
          rec[v][nt] = nc;
          que.emplace(v, nt, nc);
        }
      }

      {
        int nt = cur.tic, nc = mon + c;
        if(rec[v][nt] > nc) {
          rec[v][nt] = nc;
          que.emplace(v, nt, nc);
        }
      }
    }
  }

  CostType ans = INF;
  for(int i=0; i<=C; i++) {
    ans = min(ans, rec[D][i]);
  }
  cout << ans << endl;
  return 0;
}

int main() {
  while(!solve());
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> T;
#define INF (1 << 30)
vector<P> edge[1050];
int dist[105][15];

void dijkstra(int s, int c){
    for(int i = 0;i < 15;i++)
	for(int j = 0;j < 105;j++)
	    dist[j][i] = INF;
    dist[s][c] = 0;
    priority_queue<T> pq;
    pq.push(T(0, P(s, c)));
    while(!pq.empty()){
	T tmp = pq.top();pq.pop();
	int from = tmp.second.first, tc = tmp.second.second;
	if(dist[from][tc] < tmp.first)continue;
	for(int i = 0;i < edge[from].size();i++){
	    int to = edge[from][i].first, d = edge[from][i].second;
	    if(dist[to][tc] > dist[from][tc] + d){
		dist[to][tc] = dist[from][tc] + d;
		pq.push(T(dist[to][tc], P(to, tc)));
	    }
	    if(tc > 0 && dist[to][tc - 1] > dist[from][tc] + d / 2){
		dist[to][tc - 1] = dist[from][tc] + d / 2;
		pq.push(T(dist[to][tc - 1], P(to, tc - 1)));
	    }
	}
    }
}

int main(){
    int c, n, m, s, d, a , b, f;
    while(cin >> c >> n >> m >> s >> d, d){
	for(int i = 1;i <= n;i++){
	    edge[i].clear();
	    edge[i].push_back(P(i, 0));
	}
	for(int i = 0;i < m;i++){
	    cin >> a >> b >> f;
	    edge[a].push_back(P(b, f));
	    edge[b].push_back(P(a, f));
	}
	dijkstra(s, c);
	cout << dist[d][0] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int c,n,m,s,d;
	while(cin>>c>>n>>m>>s>>d,n){
		s--;d--;
		int cost[110][110];
		rep(i,110)rep(j,110)cost[i][j]=inf;
		while(m--){
			int a,b,e;
			cin>>a>>b>>e;
			a--;b--;
			cost[a][b]=cost[b][a]=e;
		}
		int dp[110][11];
		int used[110]={0};
		rep(i,110)rep(j,11)dp[i][j]=inf;
		dp[s][0]=0;
		while(1){
			int v=-1;
			rep(i,n)if(!used[i]&&(v==-1||dp[v][0]>dp[i][0]))v=i;
			if(v==-1)break;
			used[v]=true;
			rep(i,n)for(int j=c;j>=0;j--){
				dp[i][j]=min(dp[i][j],dp[v][j]+cost[v][i]);
				dp[i][j+1]=min(dp[i][j+1],dp[v][j]+cost[v][i]/2);
			}
		}
		//rep(i,6){rep(j,3)cout<<" "<<dp[i][j];cout<<endl;}
		int mi=inf;
		//rep(i,c+1)cout<<dp[d][i]<<endl;//mi=min(mi,dp[d][i]);
		cout<<dp[d][c]<<endl;
	}
}