Go: package main

import (
	"container/heap"
	"fmt"
)

type Node struct {
	NowPosition          int
	DiscountTicketTCount int
	Amount               int
}

type PriorityQueueNode []*Node

func (pq PriorityQueueNode) Len() int {
	return len(pq)
}

func (pq PriorityQueueNode) Less(i, j int) bool {
	return pq[i].Amount < pq[j].Amount
}

func (pq PriorityQueueNode) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueueNode) Push(node interface{}) {
	*pq = append(*pq, node.(*Node))
}

func (pq *PriorityQueueNode) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

type Point struct {
	NextPoint int
	Fee       int
}

func main() {
	var c, n, m, s, d int
	var a, b, f int

	for {
		fmt.Scan(&c, &n, &m, &s, &d)
		if c == 0 && n == 0 && m == 0 && s == 0 && d == 0 {
			break
		}
		s--
		d--
		pointMap := make([][]Point, n)
		for i := 0; i < n; i++ {
			pointMap[i] = make([]Point, 0)
		}
		for i := 0; i < m; i++ {
			fmt.Scan(&a, &b, &f)
			a--
			b--
			pointMap[a] = append(pointMap[a], Point{NextPoint: b, Fee: f})
			pointMap[b] = append(pointMap[b], Point{NextPoint: a, Fee: f})
		}
		pq := make(PriorityQueueNode, 0)
		start := Node{NowPosition: s, DiscountTicketTCount: c, Amount: 0}
		heap.Push(&pq, &start)
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				heap.Push(&pq, next)
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					heap.Push(&pq, next)
				}
			}
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

/* 現在地 コスト 使った枚数 */
typedef tuple<int,int,int> tp;
typedef pair<ll,ll> P;

/* 町 使った割引券の数 */
ll dist[105][15];
vector<P> G[105];
const ll MAX=LLONG_MAX/10;

void init(){
  for(int i=0;i<105;i++){
    G[i].clear();
    for(int j=0;j<15;j++){
      dist[i][j]=MAX;
    }
  }
}

void solve(int c,int n,int m,int s,int d){
  init();
  int a,b,f;
  for(int i=0;i<m;i++){
    cin>>a>>b>>f;
    G[a].push_back(mp(b,f));
    G[b].push_back(mp(a,f));
  }

  /* 現在地 使った枚数 */
  priority_queue<tp,vector<tp>,greater<tp> > que;
  que.push(make_tuple(s,0,0));
  dist[s][0] = 0;
  while(que.size()){
    ll now,cost,num;
    tie(now,cost,num)=que.top();que.pop();
    if(dist[now][num]<cost)continue;
    for(auto x : G[now]){      
      /* 割引券を使わない */
      if(cost+x.second<dist[x.first][num]){
        dist[x.first][num] = cost+x.second;
        que.push(make_tuple(x.first,dist[x.first][num],num));
      }
      /* 割引券が残っていたら使う */
      if(num<c&&cost+x.second/2<dist[x.first][num+1]){
          dist[x.first][num+1] = cost+x.second/2;
          // cout<<now<<" "<<x.first<<" = "<< dist[x.first][num+1] << endl;
          que.push(make_tuple(x.first,dist[x.first][num+1],num+1));
        }
    }
  }

  ll ans=LLONG_MAX;
  for(int i=0;i<15;i++)
      ans=min(ans,dist[d][i]);
  ans=min(ans,dist[d][c]);
  
  cout<<ans<<endl;
}


int main(){
  int c,n,m,s,d;
  while(cin>>c>>n>>m>>s>>d,c|n|m|s|d){
    solve(c,n,m,s,d);
  }
}

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][c] > p.F.F + po.F.S){
	MD[po.F.F][c] = p.F.F+po.F.S;
	que.push(PP(P(MD[po.F.F][c],po.F.F),c));
      }
      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<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;

#define INF 1111111111
#define F first
#define S second

struct edge {
  int to, cost;
  edge(int _to, int _cost) {to = _to; cost=_cost;}
};
typedef pair<int, pair<int, int> > P;

vector<edge> G[512];
int d[16][512];
int c, n, m, s, g;

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d[0], d[0] + 16 * 512, INF);
  d[c][s] = 0;
  que.push(P(0, pair<int, int>(s, c)));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.S.F; int w = p.S.S;
    if(d[w][v] < p.F) continue;
    for(int i = 0;i < G[v].size(); i++){
      edge e = G[v][i];
      if(d[w][e.to] > d[w][v] + e.cost){
        d[w][e.to] = d[w][v] + e.cost;
        que.push(P(d[w][e.to], pair<int, int>(e.to, w)));
      }
      if(w > 0 && d[w - 1][e.to] > d[w][v] + e.cost / 2){
	d[w - 1][e.to] = d[w][v] + e.cost / 2;
	que.push(P(d[w - 1][e.to], pair<int, int>(e.to, w - 1)));
      }
    }
  }
}

int main(void){
  int a, b, f;
  for( ; ; ){
    for(int i = 0;i < 512; i++) G[i].clear();
    scanf("%d %d %d %d %d", &c, &n, &m, &s, &g);
    if(!(c + n + m + s + g)) break;
    for(int i = 0;i < m; i++){
      scanf("%d %d %d", &a, &b, &f);
      G[a].push_back(edge(b,f));
      G[b].push_back(edge(a,f));
    }
    
    dijkstra(s);
    int ans = INF;
    for(int i = 0;i <= c; i++) ans = min(ans, d[i][g]);
    printf("%d\n", ans);
  }
}