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 <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;
	}
}