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 <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define INF 1000000000;
#define dis first
#define mati second.first
#define sta  second.second
using namespace std;
typedef pair <int ,pair <int,int> > P;
vector <P> mp[102];
int c,n,m,start,goal;

int dijkstra() {
  int flg[12][102] = {},dis[12][102];
  for(int j=0;j<=c;j++)
    for(int i=0;i<=n;i++) dis[j][i] = -INF;

  for(int j=1;j<=c;j++)flg[j][start] = 1;

  priority_queue <P> Q;
  P t;
  t.dis = 0, t.mati = start, t.sta = 0;
  Q.push(t);

  while(!Q.empty()) {
    t = Q.top(),Q.pop();
    if(flg[t.sta][t.mati] == 1) continue;
    flg[t.sta][t.mati] = 1;
    for(int i=0;i<mp[t.mati].size();i++){
      int ndis = mp[t.mati][i].dis;
      int nmati = mp[t.mati][i].mati;
      int nsta = t.sta+1;
      P tt;
      if(dis[t.sta][nmati] < t.dis-ndis && flg[t.sta][nmati] == 0) {
	tt.dis = t.dis-ndis,tt.mati = nmati,tt.sta = t.sta;
	dis[t.sta][nmati] = t.dis-ndis;
	Q.push(tt);
      }
      if(nsta<= c&&dis[nsta][nmati]<t.dis-ndis/2 && flg[nsta][nmati]==0){
	tt.dis = t.dis - ndis/2 , tt.mati = nmati, tt.sta = nsta;
	dis[nsta][nmati] = t.dis-ndis/2;
	Q.push(tt);
      }
    }
  }

  int ans = -INF;
  //  for(int j=0;j<=c;j++)ans = max(ans,dis[j][goal]);
   
  return -dis[c][goal];
}


int main() {
  while(1) {
    cin >> c >> n >> m >> start >> goal;
    if(c==0&&n==0&&m==0&&start==0&&goal==0) break;

    for(int i=0;i<=n;i++) mp[i].clear();
    for(int i=0;i<m;i++) {
      int a,b,f;
      cin >> a >> b >> f;
      P t;
      t.dis = f,  t.mati = b , t.sta = 0;
      mp[a].push_back(t);
      t.mati = a;
      mp[b].push_back(t);
    }

    cout << dijkstra() << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>

constexpr int MAX_N = 100, INF = (int)1e9;
using P = std::pair<std::pair<int, int>,int>;

struct edge {
	int to_, cost_;
	edge() = default;
	edge(int to, int cost) : to_(to), cost_(cost) {}
};

int c, n;
std::vector<edge> G[MAX_N];
int d[MAX_N];

int dijkstra(int s, int g) {
	std::fill(d, d + n, INF);
	std::priority_queue<P, std::vector<P>, std::greater<P>> que;
	d[s] = 0;
	que.emplace(std::make_pair(d[s], s), c);
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.first.second;
		if (v == g)
			break;
		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			if (p.second > 0 && d[e.to_] > d[v] + e.cost_ / 2) {
				d[e.to_] = d[v] + e.cost_ / 2;
				que.emplace(std::make_pair(d[e.to_], e.to_), p.second - 1);
			}
			if (d[e.to_] > d[v] + e.cost_) {
				d[e.to_] = d[v] + e.cost_;
				que.emplace(std::make_pair(d[e.to_], e.to_), p.second);
			}
		}
	}
	return d[g];
}

int main() {
	int m, s, g;
	while (1) {
		std::cin >> c >> n >> m >> s >> g;
		if (c + n + m + s + g == 0)
			break;
		for (int i = 0; i < n; ++i)
			G[i].clear();
		--s;
		--g;
		int a, b, f;
		for (int i = 0; i < m; ++i) {
			std::cin >> a >> b >> f;
			--a;
			--b;
			G[a].push_back(edge(b, f));
			G[b].push_back(edge(a, f));
		}
		std::cout << dijkstra(s, g) << std::endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define P pair<int,int>
using namespace std;

struct K {
	int basho, nokori, mincost;
};
bool operator<(K a, K b) {
	return a.mincost > b.mincost;
}
int main() {
	int cost[100][11];//n???????????°????????§m????????????????°????
	int B, c, d, e, f;
	while (scanf("%d%d%d%d%d", &B, &c, &d, &e, &f), B || c || d || e || f) {
		vector<P>a[100]{};
		memset(cost, 0x3f, sizeof(cost));
		e--; f--; cost[e][B] = 0;
		priority_queue<K>Q;
		K g;
		g.basho = e; g.nokori = B; g.mincost = 0;
		Q.push(g);
		for (int h = 0; h < d; h++) {
			int i, j, k;
			scanf("%d%d%d", &i, &j, &k);
			i--; j--;
			a[i].push_back(P(k, j));
			a[j].push_back(P(k, i));
		}
		while (Q.size()) {
			K l = Q.top(); Q.pop();
			int m = l.mincost, n = l.nokori, b = l.basho;
			if (cost[b][n] < m)continue;
			for (P o : a[b]) {
				if (cost[o.second][n] > cost[b][n] + o.first) {
					cost[o.second][n] = cost[b][n] + o.first;
					K xx;
					xx.basho = o.second;
					xx.mincost = cost[o.second][n];
					xx.nokori = n;
					Q.push(xx);
				}
				if (n&&cost[o.second][n-1] > cost[b][n] + o.first / 2) {
					cost[o.second][n - 1] = cost[b][n] + o.first / 2;
					K yy;
					yy.basho = o.second;
					yy.nokori = n - 1;
					yy.mincost = cost[o.second][n - 1];
					Q.push(yy);
				}
			}
		}
		int MINCOST = 1 << 29;
		for (int sss = 0; sss < 11; sss++) {
			MINCOST = min(MINCOST, cost[f][sss]);
		}
		cout << MINCOST << endl;
	}
}