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 <bits/stdc++.h>
using namespace std;

const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
const ll MOD1 = 998244353;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair

int main(){
  int c,n,m,s,d;
  while (cin >> c >> n >> m >> s >> d,c,n,m,s,d) {
    ll dp[110][11];
    REP(i,110) REP(j,11) dp[i][j] = inf;
    s--;
    d--;
    vector<pair<int,ll>> G[110];
    REP(i,m) {
      int a,b;
      ll f;
      cin >> a >> b >> f;
      a--;
      b--;
      G[a].pb({b,f});
      G[b].pb({a,f});
    }
    priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>> pq;
    dp[s][0] = 0;
    pq.push({0,{s,0}});
    while (!pq.empty()) {
      pair<ll,pair<int,int>> tp = pq.top();
      //cout << tp.fi << " " << tp.se.fi << " " << tp.se.se << endl;
      pq.pop();
      int point = tp.se.fi;
      int ticket = tp.se.se;
      if (tp.fi > dp[point][ticket]) continue;
      //cout << "test" << endl;
      REP(i,sz(G[point])) {
        int next = G[point][i].fi;
        ll cost = G[point][i].se;
        if (dp[point][ticket] + cost < dp[next][ticket]) {
          dp[next][ticket] = dp[point][ticket] + cost;
          pq.push({dp[next][ticket],{next,ticket}});
        }
        if (dp[point][ticket] + cost/2 < dp[next][ticket+1]) {
          dp[next][ticket+1] = dp[point][ticket] + cost/2;
          pq.push({dp[next][ticket+1],{next,ticket+1}});
        }
      }
    }
    cout << dp[d][c] << endl;
  }
  return 0;
}

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 });
		d[s][0] = 0;
		while (!que.empty()) {
			node p = que.top(); que.pop();
			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<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],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;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

const int INF = 1000000000;

struct Edge{
  int to,cost;
};

struct Node{
  int val,num;
};

struct P{
  int val,num,c;
  bool operator<(const P &r)const{
    return val < r.val;
  }
};




int main(){
  int c,n,m,s,d;
  
  while(1){
  cin >> c >> n >> m >> s >> d;
  s--;d--;
  if(c == 0 && n == 0 && m == 0 && s == -1 && d == -1)break;
  vector<Edge>edge[105];
  Node node[11][105];
  
  priority_queue<P> que;
  for(int i = 0; i < m; i++){
    int a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    edge[a].push_back((Edge){b,c});
    edge[b].push_back((Edge){a,c});
  }


  for(int i = 0; i < 11; i++){
    for(int j = 0; j < n; j++){
      node[i][j].val = INF;
      node[i][j].num = j;
    }
  }

  node[c][s].val = 0;
  
  que.push((P){0,s,c});

  while(!que.empty()){
    int val = que.top().val;
    int now = que.top().num;
    int ticket = que.top().c;
    que.pop();
  
    if(ticket){
      for(int i = 0; i < edge[now].size(); i++){
	int next = edge[now][i].to;
	int cost = edge[now][i].cost;

	if(node[ticket - 1][next].val > node[ticket][now].val + cost / 2){
	  node[ticket - 1][next].val = node[ticket][now].val + cost / 2;
	  que.push((P){node[ticket - 1][next].val,next,ticket - 1});
	}
      } 
    }

    for(int i = 0; i < edge[now].size(); i++){
      int next = edge[now][i].to;
      int cost = edge[now][i].cost;
      
      if(node[ticket][next].val > node[ticket][now].val + cost){
	node[ticket][next].val = node[ticket][now].val + cost;
	que.push((P){node[ticket][next].val,next,ticket});
      }
    }
  }
  
  int ans = INF;

  for(int i = 0; i < c; i++){
    ans = min(ans,node[i][d].val);
  }

  cout << ans << endl;
  }
}