Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

const INF = 0x7FFFFFFF

var pass [][]int

func main() {
	for scanner.Scan() {
		pass = make([][]int, 200)
		for i := range pass {
			pass[i] = make([]int, 200)
		}
		buf := strings.Split(scanner.Text(), " ")
		c, _ := strconv.Atoi(buf[0])
		n, _ := strconv.Atoi(buf[1])
		m, _ := strconv.Atoi(buf[2])
		s, _ := strconv.Atoi(buf[3])
		d, _ := strconv.Atoi(buf[4])
		if c == 0 && n == 0 && m == 0 && s == 0 && d == 0 {
			break
		}
		s--
		d--
		for i := 0; i < 200; i++ {
			for j := 0; j < 200; j++ {
				pass[i][j] = INF
			}
		}
		for i := 0; i < 200; i++ {
			pass[i][i] = 0
		}
		for i := 0; i < m; i++ {
			scanner.Scan()
			buf_ := strings.Split(scanner.Text(), " ")
			a, _ := strconv.Atoi(buf_[0])
			b, _ := strconv.Atoi(buf_[1])
			f, _ := strconv.Atoi(buf_[2])
			a--
			b--
			pass[a][b] = f
			pass[b][a] = f
		}
		fmt.Println(dijkstra(s, d, c, n))
	}
}

func dijkstra(s, g, c, n int) float64 {
	d := make([][]float64, 200)
	used := make([][]bool, 200)
	for i := 0; i < 200; i++ {
		d[i] = make([]float64, 20)
		used[i] = make([]bool, 20)
	}
	for i := range d {
		for j := range d[i] {
			d[i][j] = INF
		}
	}
	d[s][c] = 0
	for {
		v := -1
		w := -1
		for u := 0; u < n; u++ {
			for i := 0; i < c+1; i++ {
				if !used[u][i] && (v == -1 || d[u][i] < d[v][w]) {
					v = u
					w = i
				}
			}
		}
		if v == -1 {
			break
		}
		used[v][w] = true
		for u := 0; u < n; u++ {
			d[u][w] = math.Min(d[u][w], d[v][w]+float64(pass[v][u]))
			if w-1 >= 0 && pass[v][u] != INF {
				d[u][w-1] = math.Min(d[u][w-1], d[v][w]+(float64(pass[v][u]/2.0)))
			}
		}
	}
	ret := float64(INF)
	for i := 0; i < c+1; i++ {
		ret = math.Min(ret, d[g][i])
	}
	return ret
}

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

int calcCost(int c, int n, vector<int> path, vector<int> rt){
	priority_queue<int> costs;
	for(int i=1; i<rt.size(); i++){
		costs.push(path[rt[i]+n*rt[i-1]]);
	}
	int total = 0;
	while(costs.size() && c--){
		total += costs.top() / 2;
		costs.pop();
	}
	while(costs.size()){
		total += costs.top();
		costs.pop();
	}
	return total;
}
int main(){
	for(;;){
		int c,n,m,s,d;
		cin>>c>>n>>m>>s>>d;
		if(c+n+m+s+d==0) break;
		vector<pair<int, vector<int>>> route(n,make_pair(-1,vector<int>()));
		vector<int> path(n*n,-1);
		for(int i=0; i<m; i++){
			int a,b,f;
			cin>>a>>b>>f;
			path[--a+n*--b] = path[b+n*a] = f;
		}
		priority_queue<pair<int, vector<int>>, vector<pair<int, vector<int>>>, greater<pair<int, vector<int>>>> pq;
		pq.push(make_pair(0,vector<int>(1,s-1)));
		while(pq.size()){
			int cur = *(pq.top().second.rbegin());
			if(route[cur].first == -1){
				route[cur] = pq.top();
				for(int i=0; i<m; i++){
					if(route[i].first == -1 && path[i+n*cur] != -1){
						pair<int, vector<int>> copy = pq.top();
						copy.second.push_back(i);
						copy.first = calcCost(c,n,path,copy.second);
						pq.push(copy);
					}
				}
			}
			pq.pop();
		}
		cout<<route[d-1].first<<endl;
	}
}

C++: /*
g£_CNXg
*/
#include<iostream>
#include<queue>
#include<map>
#define INF 10000000
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int> p;
typedef pair<int,p> P;
//P(cost,p(node,ticket))
struct edge{
	int cost,to;
};
int nticket,nnode,nedge,start,goal,d[11][101];
vector<edge> v[101];
void dijkstra(){
	int nowticket,nowplace,nowsum;
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,p(start,nticket)));
	while(!que.empty()){
		P now=que.top();
		que.pop();
		
		nowsum=now.first;
		nowplace=now.second.first;
		nowticket=now.second.second;
		
		if(d[nowticket][nowplace]<nowsum)
			continue;
		rep(i,(int)v[nowplace].size()){
			edge e=v[nowplace][i];
			if(nowticket>0){
				if(d[nowticket-1][e.to]>e.cost/2+nowsum){
				d[nowticket-1][e.to]=e.cost/2+nowsum;
				que.push(P(d[nowticket-1][e.to],p(e.to,nowticket-1)));
				}
			}
			if(d[nowticket][e.to]>e.cost+nowsum){
				d[nowticket][e.to]=e.cost+nowsum;
				que.push(P(d[nowticket][e.to],p(e.to,nowticket)));
			}
		}
	}
}
void input(){
	int a,b,f;
	rep(i,nedge){
			cin>>a>>b>>f;
			a--;b--;
			edge c;
			c.cost=f;
			c.to=b;v[a].push_back(c);
			c.to=a;v[b].push_back(c);
		}
}
void init(){
	rep(i,nticket+1)
		rep(j,nnode){
			if(j==start)
			d[i][j]=0;
			else
			d[i][j]=INF;
	}
}
int main(){
	//d[ticket][node]=Å­ïp
	while(cin>>nticket>>nnode>>nedge>>start>>goal,nticket||nnode||nedge||start||goal){
		start--;goal--;
		//ticket:`Pbg
		//nnode:nodeÌ
		//nedge:edgeÌ
		//start¨goal
		input();
		init();
		dijkstra();
		int ans=INF;
		for(int i=0;i<nticket+1;i++)
		if(ans>d[i][goal])
		ans=d[i][goal];
		cout<<ans<<endl;
		for(int i=0;i<nedge;i++)
		v[i].clear();
	}
	return 0;
}

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

const int INF = 1e+9;

struct State {
  int f, v, tickets;
  State(int f, int v, int t) : f(f), v(v), tickets(t) {}
};

struct Node {
  int to, c;
  Node(int to, int c) : to(to), c(c) {}
};

bool operator > (const State& lhs, const State& rhs){
  if(lhs.f == rhs.f)
    return (lhs.v == rhs.v) ? lhs.tickets > rhs.tickets : lhs.v > rhs.v;
  else
    return lhs.f > rhs.f;
}

int N, M, C, d[101][11];
vector<Node> G[101];

void dijkstra(int s){
  for(int i = 0; i <= N; ++i)
    for(int j = 0; j <= C; ++j)
      d[i][j] = INF;
  for(int i = 0; i <= C; ++i)
    d[s][i] = 0;
  priority_queue<State, vector<State>, greater<State> > que;
  que.push(State(0, s, C));
  while(!que.empty()){
    State st = que.top();
    que.pop();
    if(d[st.v][st.tickets] < st.f)
      continue;
    for(int i = 0; i < G[st.v].size(); ++i){
      Node n = G[st.v][i];
      if(d[n.to][st.tickets] > st.f + n.c){
	d[n.to][st.tickets] = st.f + n.c;
	que.push(State(d[n.to][st.tickets], n.to, st.tickets));
      }
      if(d[n.to][st.tickets - 1] > st.f + n.c / 2){
	d[n.to][st.tickets - 1] = st.f + n.c / 2;
	que.push(State(d[n.to][st.tickets - 1], n.to, st.tickets - 1));
      }
    }
  }
}


int main() {
  int s, e, a, b, f;
  while(cin >> C >> N >> M >> s >> e && (N || M || C || s || e)){
    for(int i = 0; i <= 100; ++i)
      G[i].clear();
    for(int i = 0; i < M; ++i){
      scanf("%d%d%d", &a, &b, &f);
      G[a].push_back(Node(b, f));
      G[b].push_back(Node(a, f));
    }
    dijkstra(s);
    int ans = INF;
    for(int i = 0; i <= C; ++i)
      ans = min(ans, d[e][i]);
    cout << ans << endl;
  }
  return 0;
}

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

#define INF 1010000000
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)
#define sint(i) scanf("%d",&i);
#define sintt(i,j) scanf("%d%d",&i,&j);
#define sinttt(i,j,k) scanf("%d%d%d",&i,&j,&k);

using namespace std;

class S{
	public:
	int p;
	int v;
	int n;
	
	S(int p,int v,int n):p(p),v(v),n(n){}
	
	bool operator<(const S&a)const{
		return v>a.v;
	}
};

int main(){
	while(1){
		int c,n,m,s,g;
		scanf("%d%d%d%d%d",&c,&n,&m,&s,&g);
		if(c==0)break;
		
		int root[101][101];
		rep(i,101)rep(j,101)root[i][j]=INF;
		
		rep(i,m){
			int a,b,d;
			sinttt(a,b,d);
			root[a][b]=d;
			root[b][a]=d;
		}
		
		priority_queue<S> qui;
		qui.push(S(s,0,0));
		int ans=0;
		
		int visit[101][11];
		rep(i,101)rep(j,11)visit[i][j]=0;
		
		while(1){
			if(qui.empty()==1){
				ans=-1;
				break;
			}
			
			S u=qui.top();qui.pop();
			
			if(u.p==g){
				ans=u.v;
				break;
			}
			
			//printf("%d %d %d\n",u.p,u.v,u.n);
			visit[u.p][u.n]=1;
			
			reps(i,n){
				if(root[u.p][i]!=INF){
					if(visit[i][u.n]==0){
						qui.push(S(i,u.v+root[u.p][i],u.n));
					}
					if(visit[i][u.n+1]==0 && visit[u.p][u.n+1]==0 && u.n+1 <= c){
						qui.push(S(i,u.v+root[u.p][i]/2,u.n+1));
					}
				}
			}
		}
		printf("%d\n",ans);
	}
}