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 <vector>
#include <queue>
using namespace std;
 
#define MAX 10000000
#define n_MAX 101
#define c_MAX 11

typedef pair<int, pair<int, int> > edge;

int get_cost(const edge& e){
  return e.first;
}

int get_tickets(const edge& e){
  return -(e.second.first);
}

int get_station(const edge& e){
  return e.second.second;
}

inline edge make_edge(int cost, int tickets, int station){
  return make_pair(cost, make_pair(-tickets, station));
}

int main() {
 
  while( true ) {
    
    long long int c, n, m, s, d;
    cin >> c >> n >> m >> s >> d;
    if ( n == 0 ) break;
    
    long long int l[n_MAX][n_MAX] = {0};
    
    for ( long long int i = 0; i < m; i++ ) {
      long long int a, b, f;
      cin >> a >> b >> f;
      l[a][b] = l[b][a] = f;
    }
 
    long long int t[c_MAX][n_MAX];
    for ( long long int j = 0; j <= c; j++ ) {
      for ( long long int i = 1; i <= n; i++ ) {
	t[j][i] = MAX;
      }
    }
    
    priority_queue<edge, vector<edge>, less<edge> > queue;
    queue.push(make_edge(0, c, s));
    t[c][s] = 0;

    int ans = MAX;
    while(!queue.empty()){
      edge e = queue.top(); queue.pop();

      const int cost = get_cost(e);
      const int tickets = get_tickets(e);
      const int station = get_station(e);
      if(t[tickets][station] > cost){
	continue;
      }else if(station == d){
	ans = min(ans, cost);
      }

      for(long long int next = 1; next <= n; next++){
	if(l[station][next] == 0){
	  continue;
	}
	
	const int next_non_use_cost = cost + l[station][next];
	const int next_use_cost     = cost + l[station][next] / 2;
 
	if(tickets > 0 && t[tickets - 1][next] > next_use_cost){
	  t[tickets - 1][next] = next_use_cost;
	  queue.push(make_edge(next_use_cost, tickets - 1, next));
	}
	
	if(t[tickets][next] > next_non_use_cost){
	  t[tickets][next] = next_non_use_cost;
	  queue.push(make_edge(next_non_use_cost, tickets, next));
	}
      }
    }
 
    cout << ans << endl;
  }
 
  return 0;
 
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <map>
#define INF (1 << 26)
#define fr first
#define sc second
using namespace std;

typedef pair<int,int> S;
typedef pair<S,int> P;
struct edge{
    int to,cost; edge(){}
    edge(int to,int cost):to(to),cost(cost){}
};

int c,n,m,s,d,costed[1024][101];
vector< vector<edge> > info(1024);

void init(){
    for(int i=0;i<1024;i++){
        for(int j=0;j<101;j++) costed[i][j] = INF;
    }
    info.resize(0); info.resize(1024);
}

void add_info(){
    int a,b,f;
    cin >> a >> b >> f;
    info[a].push_back(edge(b,f));
    info[b].push_back(edge(a,f));
}

int Dijkstra(){
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(S(0,s),c));  costed[s][c] = 0;
    while(!que.empty()){
        P p = que.top(); que.pop();
        int now = p.fr.sc,c = p.fr.fr,tic = p.sc;
        if(now == d) return c;
        for(int i=0;i<info[now].size();i++){
            edge e = info[now][i];
            if(e.cost + c < costed[e.to][tic]){
                que.push(P(S(e.cost+c,e.to),tic));
                costed[e.to][tic] = e.cost + c;
            }
            if(tic != 0){
                if(e.cost/2 + c < costed[e.to][tic-1]){
                    que.push(P(S(c+e.cost/2,e.to),tic-1));
                    costed[e.to][tic-1] = e.cost/2 + c;
                }
            }
        }
    }
}

int main(){
    while(cin>>c>>n>>m>>s>>d,c||n||m||s||d){
        init();
        for(int i=0;i<m;i++) add_info();
        cout << Dijkstra() << endl;
    }
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
struct edge{int to,cost;};
int dp[100][11];
vector<edge> G[100];
int main(){
      int c,n,m,s,d;
      while(cin>>c>>n>>m>>s>>d&&(c||n||m||s||d)){
            s--;d--;
            REP(i,100)REP(j,11)dp[i][j]=INF;
            REP(i,100)G[i].clear();
            REP(i,m){
                  int x,y,z;
                  cin>>x>>y>>z;x--;y--;
                  G[x].PB((edge){y,z});
                  G[y].PB((edge){x,z});
            }
            dp[s][0]=0;
            queue<int> Q;
            Q.push(s);
            while(!Q.empty()){
                  int v=Q.front();Q.pop();
                  //cout<<v<<" "<<G[v].size()<<endl;
                  REP(i,G[v].size()){
                        bool f=false;
                        edge e=G[v][i];
                        int to=e.to;
                        REP(i,c+1){
                              //cout<<dp[v][i]+e.cost<<endl;;
                              if(dp[to][i]>dp[v][i]+e.cost){
                                    dp[to][i]=dp[v][i]+e.cost;
                                    f=true;
                              }
                        }
                        REP(i,c){
                              if(dp[to][i+1]>dp[v][i]+e.cost/2){
                                    dp[to][i+1]=dp[v][i]+e.cost/2;
                                    f=true;
                              }
                        }
                        if(f)Q.push(to);
                  }
            }
            int ans=INF;
            REP(i,c+1)ans=min(ans,dp[d][i]);
            cout<<ans<<endl;
      }
}