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
}

type Memo struct {
	NowPoint             int
	DiscountTicketTCount 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, n)
		}
		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, m)
		start := Node{NowPosition: s, DiscountTicketTCount: c, Amount: 0}
		heap.Push(&pq, &start)
		memo := make(map[Memo]struct{})
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			memo[Memo{NowPoint: now.NowPosition, DiscountTicketTCount: now.DiscountTicketTCount}] = struct{}{}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if _, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok {
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if _, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok {
						heap.Push(&pq, next)
					}
				}
			}
		}
	}
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
const int MAX_V =100;

int c,n,m,d;//割引券,街の数,路線の数,出発地,目的地
int a,b,f;//バスの始点、終点,料金
int cd[11][MAX_V];
int used[MAX_V];
int cost[MAX_V][MAX_V];
const int INF =10000000;
int mv;
int max1,max2;
int max1V,max2V;
void dijkstra(int s){
  for(int i = 0;i <=c;i++){
    for(int j = 0;j <n;j++){
      if(j !=s)
	cd[i][j] =INF;
      else
	cd[i][s] =0;
    }
  }
  int v;
  for(int k = 0;k <=c;k++){
    fill(used,used+MAX_V,-1);
    while(true){
      v = -1;
    for(int u = 0;u <n;u++){
      if(used[u] ==-1&&(v ==-1||cd[k][u]<cd[k][v]))
	v =u;
    }
    if(v ==-1)
      break;
    used[v] =1;
   
    for(int u = 0;u <n;u++){
      if(used[u] ==-1){
      if(k ==0){
	cd[k][u] =min(cd[k][u],cd[k][v]+cost[v][u]);
      }
      else{
	cd[k][u] = min(cd[k][u],min(cd[k][v]+cost[v][u],cd[k-1][v]+cost[v][u]/2));
      }
      }
    }
    }
  }
}
int main()
{
  int s;
  while(cin >>c>>n>>m>>s>>d){
    if(c+n+m+s+d ==0)
      break;
  for(int i = 0;i <n;i++){
    for(int j = 0;j < n;j++){
      if(i !=j)
	cost[i][j] =INF;
      else
	cost[i][j] = 0;
    }
  }
  for(int i = 0;i < m;i++){
    cin >>a>>b>>f;
    cost[a-1][b-1] = f;
    cost[b-1][a-1] = f;
  }
  dijkstra(s-1);
  cout <<cd[c][d-1]<<endl;
  }
  return 0;
}

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;
}