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<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  unsigned i,j;
  unsigned a[100][100],b[100][11],c[100][11],m,n,o,u,v;
  pair<pair<unsigned,unsigned>,unsigned> mn;
  while(cin>>m>>n>>o>>u>>v&&m+n+o+u+v){
    u--;
    v--;
    memset(a,-1,sizeof(a));
    for(i=0;i<o;i++){
      int p,q,r;
      cin>>p>>q>>r;
      p--;
      q--;
      a[p][q]=a[q][p]=r;
    }
    memset(b,0,sizeof(b));
    memset(c,-1,sizeof(c));
    c[u][0]=0;
    mn.first.first=u;
    mn.first.second=0;
    mn.second=0;
    while(mn.first.first!=v){
      b[mn.first.first][mn.first.second]=1;
      for(i=0;i<n;i++){
	if((int)a[mn.first.first][i]!=-1){
	  c[i][mn.first.second]=min(c[i][mn.first.second],mn.second+a[mn.first.first][i]);
	  if(mn.first.second<m)
	    c[i][mn.first.second+1]=min(c[i][mn.first.second+1],mn.second+a[mn.first.first][i]/2);
	}
      }
      mn.second=-1;
      for(i=0;i<m+1;i++){
	for(j=0;j<n;j++){
	  if(b[j][i]==0&&mn.second>c[j][i]){
	    mn.first.first=j;
	    mn.first.second=i;
	    mn.second=c[j][i];
	  }
	}
      }
    }
    cout<<mn.second<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;// F -> to, S -> cost
typedef pair<P,int> PP;// F->P(to,cost), S->discount
int c,n,m,s,d;
vector<PP> vec[1000];
int MD[1000][13];
const int INF = 1<<29;

void dijkstra(){
  priority_queue<PP,vector<PP>,greater<PP> > que;
  rep(i,n+1)rep(j,13)MD[i][j] = INF;
  //syokika
  MD[s][c] = 0;
  que.push(PP(P(0,s),c));//dis,start,discount

  while(!que.empty() ){
    PP p = que.top();que.pop(); //priority_queのPPと
    int v = p.F.S;
    
    for(int i=0;i<vec[v].size();i++){
      PP po = vec[v][i]; //vectorのPPは意味が違うので注意！！！
      //if(MD[v][po.S] < po.F.S)continue;
      if(MD[po.F.F][p.S] > p.F.F + po.F.S){
	MD[po.F.F][p.S] = p.F.F+po.F.S;
	que.push(PP(P(MD[po.F.F][p.S],po.F.F),p.S));
      }
      if(po.S > 0 && MD[po.F.F][p.S-1] > p.F.F + po.F.S/2 ){
	MD[po.F.F][p.S-1] = p.F.F+po.F.S/2;
	que.push(PP(P(MD[po.F.F][p.S-1],po.F.F),p.S-1));
	vec[v][i].S--;
      }
    }
  }
}


int main(){
  int x,y,co;
  while(true){
    cin >> c >> n >> m >> s >> d;
    if(c+n+m+s+d == 0)break;
    rep(i,1000)vec[i].clear();
    rep(i,m){
      cin >> x >> y >> co;
      vec[x].push_back(PP(P(y,co),c));
      vec[y].push_back(PP(P(x,co),c));
    }
    dijkstra();
    int ans = INF;
    for(int i=0;i<=c;i++){
      ans = min(ans,MD[d][i]);
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  using P = pair<int,int>;
  int c,n,m,s,t;
  while(cin>>c>>n>>m>>s>>t, c|n|m){
    s--;t--;
    vector<vector<P>> vec(n);
    rep(i,m){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      vec[a].pb(mp(f,b));
      vec[b].pb(mp(f,a));
    }

    vector<vector<int>> d(m,vector<int>(c+1,INF));
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push(mp(0,s*(c+1)));
    d[s][c] = 0;
    while(!pq.empty()){
      auto p = pq.top(); pq.pop();
      int v = p.se/(c+1);
      int k = p.se%(c+1);
      if(d[v][k] < p.fi) continue;

      auto go = [&](int nv, int nk, int dist){
        if(d[nv][nk] > dist){
          pq.push(mp(dist, nv*(c+1)+nk));
          d[nv][nk] = dist;
        }
      };

      for(auto to : vec[v]){
        go(to.se, k, p.fi + to.fi);
        if(k<c) go(to.se, k+1, p.fi + to.fi/2);
      }
    }

    cout << *min_element(all(d[t])) << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>

using namespace std;

int c,n,m,s,d;
vector<pair<int,int> >  v[101];
int dp[101][11];

int inf = 1111111111;

typedef pair<pair<int,int>,int> p;

void dijkstra(int s,int ticket){
  priority_queue<p,vector<p>,greater<p> > que;
  
  fill((int *)dp,(int *)dp+101*11,inf);
  dp[s][0] = 0;
  que.push(make_pair(make_pair(0,s),0));

  while(!que.empty()){
    p x = que.top();
    que.pop();
    int V = (x.first).second;
    if(dp[V][x.second] < (x.first).first)
      continue;
    for(int i = 0;i<v[V].size();i++){
      pair<int,int> tmp = v[V][i];
      if(dp[tmp.first][x.second] > dp[V][x.second] + tmp.second){
	dp[tmp.first][x.second] = dp[V][x.second] + tmp.second;
	que.push(make_pair(make_pair(dp[tmp.first][x.second],tmp.first),x.second));
      }

      if(x.second < ticket && dp[tmp.first][x.second+1] > dp[V][x.second] + tmp.second/2) {
	//cout<<"a"<<endl;
	dp[tmp.first][x.second+1] = dp[V][x.second] + tmp.second/2;
	que.push(make_pair(make_pair(dp[tmp.first][x.second+1],tmp.first),x.second+1));
      }		

    }

  }
}


int main(){

  while(cin>>c>>n>>m>>s>>d){
    if(c==0&&n==0&&m==0&&s==0&&d==0)
      break;
  
    for(int i = 0;i<101;i++){
      v[i].clear();
    }
    s--;
    d--;
    for(int i = 0;i<m;i++){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      v[a].push_back(make_pair(b,f));
      v[b].push_back(make_pair(a,f));
    }
    dijkstra(s,c);
    /*
    for(int i = 0;i<=c;i++){
      ans = min(ans,dp[d][i]);
    }
    */
    /*
    for(int i = 0;i<=c;i++){
      for(int j = 0;j< n;j++){
	cout<<dp[j][i]<<" ";
      }
      cout<<endl;
    }
    */
    cout<<dp[d][c]<<endl;
  }

  return 0;
}