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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi; // 残りの割引券 現在の街
typedef pair<int, pi>P; // コスト pi
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

struct edge{ int to, cost; };

int C, V, E, S, D;
int d[128][16];
vector<vector<edge> >G(100);

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> >q;
  rep(i, V) rep(j, C) d[i][j] = INF;
  d[s][C] = 0;
  q.push(MP(0, MP(C, s)));

  while(!q.empty()){
    P p = q.top(); q.pop();
    int v = p.S.S;
    int c = p.S.F;

    rep(i, G[v].size()){
      edge e = G[v][i];
      if(d[e.to][c] > d[v][c] + e.cost){
	d[e.to][c] = d[v][c] + e.cost;
	q.push(MP(d[e.to][c], MP(c, e.to)));
      }

      if(C > 0){
	//	int cost = (e.cost/2)/100*100;
	if(d[e.to][c-1] > d[v][c] + e.cost/2){
	  d[e.to][c-1] = d[v][c] + e.cost/2;
	  q.push(MP(d[e.to][c-1], MP(c-1, e.to)));
	}
      }
    }
  }
}

int main(){
  while(scanf("%d%d%d%d%d", &C, &V, &E, &S, &D) && C+V+E+S+D){
    S--; D--;
    rep(i, V){
      G[i].clear();
    }
    rep(i, E){
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c); a--; b--;
      edge e;
      e.to = a; e.cost = c;
      G[b].PB(e);
      e.to = b;
      G[a].PB(e);
    }

    dijkstra(S);

    printf("%d\n", d[D][0]);
  }

  return 0;
}

C++: #include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define INF (1<<24)
 
struct state{
  int cost,pos,cnt;
  bool operator < (const state &p) const{
    return cost>p.cost;
  }
};
 
struct edge{
  int to,cost;
};
 
int c,n,m,s,d;
vector<edge> G[100];
 
void init(){
  for(int i=0;i<100;i++)G[i].clear();
}
 
int dijkstra(int si,int ti){
  int d[100][11];
  for(int i=0;i<100;i++)
    for(int j=0;j<11;j++)d[i][j]=INF;
 
  d[si][c]=0;
  priority_queue< state > Q;
  Q.push((state){0,si,c});
 
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(s.cost>d[s.pos][s.cnt])continue;
 
    for(int i=0;i<(int)G[s.pos].size();i++){
      edge e=G[s.pos][i];
      if(s.cost+e.cost>=d[e.to][s.cnt])continue;
      d[e.to][s.cnt]=s.cost+e.cost;
      Q.push((state){s.cost+e.cost,e.to,s.cnt});
    }
 
    if(s.cnt==0)continue;
 
    for(int i=0;i<(int)G[s.pos].size();i++){
      edge e=G[s.pos][i];
      if(s.cost+e.cost/2>=d[e.to][s.cnt-1])continue;
      d[e.to][s.cnt-1]=s.cost+e.cost/2;
      Q.push((state){s.cost+e.cost/2,e.to,s.cnt-1});
    }
  }//while
 
  int res=INF;
  for(int i=0;i<=c;i++){
    res=min(res,d[ti][i]);
  }
  return res;
}
 
int main(){
  int a,b,f;
  while(cin>>c>>n>>m>>s>>d){
    if(n==0)break;
    init();
    for(int i=0;i<m;i++){
      cin>>a>>b>>f;
      a--;b--;
      G[a].push_back((edge){b,f});
      G[b].push_back((edge){a,f});
    }
    cout<<dijkstra(s-1,d-1)<<endl;
  }
  return 0;
}

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

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define INF 1e8

struct edge {
    int to, cost;
};

struct P {
    int from, cost, ticket;

    bool operator >(const P& p) const {
        return cost > p.cost;
    }
};

const int dx[] = {-1,0,1,0}; const int dy[] = {0,1,0,-1};

int ticket_n, node_n, edge_n, start, goal;

int main() {
    while (cin >> ticket_n >> node_n >> edge_n >> start >> goal, ticket_n|node_n|edge_n|start|goal) {
        vector<vector<edge>> E(edge_n+1);
        REP(i, edge_n) {
            int from, to, cost;
            cin >> from >> to >> cost;
            E[from].push_back({to, cost});
            E[to].push_back({from, cost});
        }

        vvi G(edge_n+1, vi(ticket_n+1, INF));
        priority_queue<P, vector<P>, greater<P>> q;
        q.push({start, 0, ticket_n});
        while (!q.empty()) {
            P p = q.top(); q.pop();

            if (p.from == goal) {
                cout << p.cost << endl;
                break;
            }

            int from = p.from, cost = p.cost, ticket = p.ticket;
            for (edge e : E[from]) {
                // use ticket
                if (G[e.to][ticket] > cost + e.cost) {
                    G[e.to][ticket] = cost + e.cost;
                    q.push({e.to, cost + e.cost, ticket});
                }
                // don't use ticket
                if (ticket-1 >= 0) {
                    if (G[e.to][ticket-1] > cost + e.cost/2) {
                        G[e.to][ticket-1] = cost + e.cost/2;
                        q.push({e.to, cost + e.cost/2, ticket-1});
                    }
                }
            }
        }
    }
}