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<algorithm>
#include<queue>
#include<vector>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> PP;
int graph[110][110];
int c,n,m,s,d;
int D[110][15];
const int INF = 1<<28;

void Init(){
  for(int i=0;i<110;i++){
    for(int k=0;k<110;k++){
      graph[i][k] = INF;
    }
    for(int j=0;j<15;j++){
      D[i][j] = INF;
    }
  }

}


void dijkstra(){
  priority_queue<PP,vector<PP>,greater<PP> > que;
  D[s][c] = 0;
  // PP( P(pos,cost), c )
  // .F.F -> pos
  // .F.S -> cost
  // .S   -> c
  que.push(PP(P(s,0),c));
  while(!que.empty() ){
    PP p = que.top();que.pop();
    int v = p.F.F;
    for(int i=1;i<=n;i++){
     
      if(D[i][p.S] > graph[v][i] + p.F.S){
	D[i][p.S] = graph[v][i] + p.F.S;
	que.push(PP(P(i,D[i][p.S]),p.S));
      }

      if(D[i][p.S-1] > graph[v][i]/2 + p.F.S && p.S != 0){
	D[i][p.S-1] = graph[v][i]/2 + p.F.S;
	que.push(PP(P(i,D[i][p.S-1]),p.S-1));
      }


    }


  }

}

int main(){
  int x,y,co;
  while(true){
    cin >> c >> n >> m >> s >> d;
    if(c+n+m+s+d == 0)break;
    Init();

    for(int i=0;i<m;i++){
      cin >> x >> y >> co;
      graph[x][y] = graph[y][x] = co;
    }


    dijkstra();
    int ans = INF;
    for(int i=0;i<=c;i++)ans = min(ans,D[d][i]);
    cout<< ans << endl;
  }
  return 0;
}


//Version.2

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef pair<int, int>P;

struct node {
	int first, second, c;
};
bool operator<(node a, node b) {
	return a.second > b.second;
}
vector<P>E[100];
int d[100][11];

int main() {
	int c, n, m, s, g;
	while (scanf("%d%d%d%d%d", &c, &n, &m, &s, &g), c) {
		s--; g--;
		rep(i, 100)E[i].clear();
		memset(d, 0x3f, sizeof(d));
		rep(i, m) {
			int a, b, f; scanf("%d%d%d", &a, &b, &f);
			a--; b--;
			E[a].push_back(P(b, f)); E[b].push_back(P(a, f));
		}
		priority_queue<node>que;
		que.push({ s,0,c });
		memset(d[s], 0, sizeof(d[s]));
		while (!que.empty()) {
			node p = que.top(); que.pop();
			if (d[p.first][p.c - 1] < p.second)continue;
			for (P i : E[p.first]) {
				if (p.c&& d[i.first][p.c - 1] > p.second + i.second / 2) {
					d[i.first][p.c - 1] = p.second + i.second / 2;
					que.push({ i.first, d[i.first][p.c - 1],p.c - 1 });
				}
				if (d[i.first][p.c] > p.second + i.second) {
					d[i.first][p.c] = p.second + i.second;
					que.push({ i.first, d[i.first][p.c],p.c });
				}
			}
		}
		int Min = INT_MAX;
		rep(i, c + 1)Min = min(Min, d[g][i]);
		printf("%d\n", Min);
	}
}

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

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

struct edge{
    int to, cost;
};

typedef pair<int, pair<int, int> > pii; // distance, edge, ticket

int INF = 10e8;
int c, n, m, s, d;

int dis[100][11];

int main(){
    while(1){
        cin >> c >> n >> m >> s >> d;

        if(n==0) break;

        vector<edge> g[100];
        REP(i, m){
            int a, b, f;
            cin >> a >> b >> f;
            edge ae;
            ae.to = b;
            ae.cost = f;
            g[a].push_back(ae);
            edge be;
            be.to = a;
            be.cost = f;
            g[b].push_back(be);
        }

        priority_queue<pii, vector<pii>, greater<pii> > que;
        REP(i, n+1){
            REP(j, c+1){
                dis[i][j] = INF;
            }
        }
        dis[s][c] = 0;
        pii init = make_pair(0, make_pair(s, c));
        que.push(init);

        while(!que.empty()){
            pii p = que.top();
            que.pop();

            int v = p.second.first;
            int t = p.second.second;
            if(dis[v][t]<p.first) continue;
            REP(i, g[v].size()){
                edge e = g[v][i];
                if(dis[e.to][t] > dis[v][t] + e.cost){
                    dis[e.to][t] = dis[v][t] + e.cost;
                    que.push(pii(make_pair(dis[e.to][t], make_pair(e.to, t))));
                }
                if(t>0){
                    if(dis[e.to][t-1] > dis[v][t] + e.cost / 2){
                        dis[e.to][t-1] = dis[v][t] + e.cost / 2;
                        que.push(pii(make_pair(dis[e.to][t-1], make_pair(e.to, t-1))));
                    }
                }
            }
        }
        /*
        REP(i, n+1){
            REP(j, c+1){
                cout << dis[i][j] << " ";
            }
            cout << endl;
        }
        */
        cout << dis[d][0] << endl;
    }
}

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

#define MAX 100
#define INF 1000000
int G[MAX][MAX];
int c, n, m, s, d, a, b, f;

int dijkstra(){
    int D[MAX][11];
    bool visited[MAX][11];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= c; j++) {
            D[i][j] = INF;
            visited[i][j] = false;
        }
    }
    D[s][c] = 0;
    while (true) {
        int u = 0, w = 0, minv = INF;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= c; j++) {
                if (!visited[i][j] && minv > D[i][j]) {
                    minv = D[i][j];
                    u = i;
                    w = j;
                }
            }
        }
        if (minv == INF) {
            break;
        }
        visited[u][w] = true;
        for (int v = 0; v < n; v++) {
            if (G[u][v] == INF) {
                continue;
            }
            D[v][w] = min(D[v][w], D[u][w] + G[u][v]);
            if (w) {
                D[v][w-1] = min(D[v][w-1], D[u][w] + G[u][v] / 2);
            }
        }
    }
    int minv = INF;
    for (int i = 0; i <= c; i++) {
        minv = min(minv, D[d][i]);
    }
    return minv;
}

int main()
{
    while (true) {
        cin >> c >> n >> m >> s >> d;
        if (s == 0 && d == 0) {
            break;
        }
        s--;
        d--;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                G[i][j] = INF;
            }
        }
        for (int i = 0; i < n; i++) {
            cin >> a >> b >> f;
            a--;
            b--;
            G[a][b] = G[b][a] = f;
        }
        cout << dijkstra() << endl;
    }

    return 0;
}