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

struct edge { 
  int to, cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
typedef pair<int ,int> P;
const int INF = 1 << 30;
int V; //ノードの数
vector<edge> Graph[MAX_V];
int min_cost[11][MAX_V];

int c,m,s,d;
void Dijkstra(int s,int chip){ // s:スタートからの最小コストをmin_costに設定
  priority_queue<P,vector< P >, greater<P> > que;
  min_cost[chip][s] = 0;
  que.push(P(0,s));
  
  while(!que.empty()){
    P p = que.top();que.pop();
    int now = p.second;
    int cost = p.first;
    if(min_cost[chip][now] < cost) continue;
    
    for(int i = 0; i < Graph[now].size(); i++){
      edge e = Graph[now][i];
      int a;
      if(chip == 0){
	a = min_cost[chip][now] + e.cost;
      }else{
	a = min(min_cost[chip][now] + e.cost, min_cost[chip-1][now] + e.cost / 2);
      }
      if(min_cost[chip][e.to] > a){
	min_cost[chip][e.to] = a;
	que.push(P(min_cost[chip][e.to], e.to));
      }
    }
  }
}

int main(){
  
  while(cin >> c >> V >> m >> s >> d && (c||V||m||s||d)){
    s--;
    d--;
    
    for(int i=0;i<m;i++){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      Graph[a].push_back(edge(b,f));
      Graph[b].push_back(edge(a,f));
    }
    for(int i=0;i<=c;i++){
      for(int j=0;j<MAX_V;j++){
	min_cost[i][j] = INF;
      }
    }
    for(int i=0;i<=c;i++){
      Dijkstra(s,i);
    }

    cout<<min_cost[c][d]<<endl;
    
    for(int i=0;i<MAX_V;i++) Graph[i].clear();
  }
  return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

#define INIT INF
typedef int Weight;
typedef pair<Weight,int> P;

typedef pair<P,int> PP;

int c,n,m,s,g;

struct Edge {
	int to;
	Weight cost;
	Edge(int to,Weight cost):to(to),cost(cost) {}
};

typedef vector< vector<Edge> > Graph;

bool operator<(const Edge &e,const Edge &f) {
	return e.cost!=f.cost?e.cost>f.cost:e.to<f.to;
}

void dijkstra(const Graph &G,int s,vector< vector<Weight> > &dist) {
	int n=(int)G.size();
	dist.assign(n,vector<Weight>(c+1,INIT));
	dist[s][0]=0;
	priority_queue< PP,vector<PP>,greater<PP> > Q;
	Q.push(PP(P(0,s),0));
	while(!Q.empty()) {
		PP p=Q.top();Q.pop();
		int v=p.first.second,times=p.second;
		if(dist[v][times]<p.first.first) continue;
		for(auto e:G[v]) {
			if(dist[e.to][times]>dist[v][times]+e.cost) {
				dist[e.to][times]=dist[v][times]+e.cost;
				Q.push(PP(P(dist[e.to][times],e.to),times));
			}
			if(times+1<=c&&dist[e.to][times+1]>dist[v][times]+e.cost/2) {
				dist[e.to][times+1]=dist[v][times]+e.cost/2;
				Q.push(PP(P(dist[e.to][times+1],e.to),times+1));
			}
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>c>>n>>m>>s>>g;
	s--,g--;
	Graph G(n);
	vector< vector<Weight> > dist(n,vector<Weight>(c+1));
	REP(i,m) {
		int a,b;Weight c;
		cin>>a>>b>>c;
		a--,b--;
		G[a].emplace_back(b,c);
		G[b].emplace_back(a,c);
	}
	dijkstra(G,s,dist);
	Weight ans=INIT;
	REP(i,c+1) ans=min(ans,dist[g][i]);
	cout<<ans<<endl;

	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

struct edge {
    int to, cost;
};

struct state {
    int v, d, rest;
    bool operator<(const state& s)const{
        return d>s.d;
    }
};

int dijk(int s, int g, vector<vector<edge>> G, int c){

    vector<int> d(G.size(), 1 << 30);
    d[s] = 0;
    priority_queue<state> q;
    q.push({ s, 0, c });

    while (q.size()){
        state sta = q.top();
        q.pop();

        int v = sta.v;

        if (d[v] > sta.d) continue;

        int rest = sta.rest;
        rep(i, G[v].size()){
            int to = G[v][i].to;
            int cost = G[v][i].cost;

            if (d[to] > sta.d + cost){
                d[to] = sta.d + cost;
                q.push({ to, sta.d + cost, rest});
            }

            if (!!rest && d[to] > sta.d + cost/2){
                d[to] = sta.d + cost / 2;
                q.push({ to, sta.d + cost / 2, rest - 1 });
            }
        }
    }
    return d[g];
}

int main(){
    while (1){
        int c, V, E, s, d;
        cin >> c >> V >> E >> s >> d;
        if (V == 0) break;
        vector<vector<edge>> G(V);
        s--; d--;
        rep(i, E){
            int a, b, c;
            cin >> a >> b >> c;
            a--; b--;
            G[a].push_back({ b, c });
            G[b].push_back({ a, c });
        }
        cout << dijk(s, d, G, c) << endl;
    }
}