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 <string>
#include <vector>
using namespace std;

struct Edge { int from, to, cost; };
vector<Edge> edges;

int mincost[11][101];

int main() {
    int c, n, m, s, d;
    while (cin >> c >> n >> m >> s >> d, c) {
        edges.clear();
        int a, b, f;
        for (int i=0; i<m; ++i) {
            cin >> a >> b >> f;
            edges.push_back((Edge){ a, b, f });
            edges.push_back((Edge){ b, a, f });
        }
        for (int i=0; i<11; ++i) {
            for (int j=0; j<101; ++j) {
                mincost[i][j] = 10000000;
            }
        }
        mincost[0][s] = 0;
        for (int k=0; k<n; ++k) {
            for (int i=0; i<(int)edges.size(); ++i) {
                Edge &e = edges[i];
                for (int j=0; j<=c; ++j) {
                    mincost[j][e.to] = min(mincost[j][e.to], mincost[j][e.from] + e.cost);
                    if (j < c) {
                        mincost[j+1][e.to] = min(mincost[j+1][e.to], mincost[j][e.from] + e.cost / 2);
                    }
                }
            }
        }
        int res = 10000000;
        for (int i=0; i<10; ++i) {
            res = min(res, mincost[i][d]);
        }
        cout << res << endl;
    }
    return 0;
}

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

using namespace std;

typedef pair<int,pair<int,int> >P;

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

int minCost[102][12];
vector<Edge> edge[102];
static const int INF = INT_MAX;

int c,n,m,s,d;

int dijkstra(void){
  priority_queue<P, vector<P>, greater<P> >que;
  que.push(make_pair(0,make_pair(s,c)));

  for(int i=0;i<=n;i++)
    for(int j=0;j<=n;j++)
      minCost[i][j]=INF;

  while(!que.empty()){
    P p = que.top();
    que.pop();

    if(p.second.first==d)return p.first;
    
    for(int i=0;i<edge[p.second.first].size();i++){
      Edge e = edge[p.second.first][i];
      if(p.first+e.cost < minCost[e.to][p.second.second]){
	minCost[e.to][p.second.second] = p.first+e.cost;
	que.push(make_pair(p.first+e.cost,make_pair(e.to,p.second.second)));
      }
    }
    
    if(p.second.second==0)continue;
    
    for(int j=0;j<edge[p.second.first].size();j++){
      Edge e = edge[p.second.first][j];
      if(p.first+e.cost/2 < minCost[e.to][p.second.second-1]){
	minCost[e.to][p.second.second-1] = p.first+e.cost/2;
	que.push(make_pair(p.first+e.cost/2,make_pair(e.to,p.second.second-1)));
      }
    }
  }
  return -1;
}

int main(void){
  int a,b,f;

  while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){

    for(int i=0;i<=n;i++)edge[i].clear();

    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      edge[a].push_back(Edge(b,f));
      edge[b].push_back(Edge(a,f));
    }

    cout << dijkstra() << endl;
  }

  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<utility>
#include<queue>
#include<algorithm>
using namespace std;
#define INF 100000000
int C,N,M,S,D,g1[101][101],g2[101][101],s,t,c,d[101],u[101];
typedef struct P{int p,c,t;}P;
struct Order
{
	bool operator ()(P const& a, P const& b) const
	{
		return a.c==b.c?a.t<b.t:a.c>b.c;
	}
};

P tmp,tmp2;
priority_queue<P,vector<P>,Order>Q;
int main()
{
	for(;scanf("%d%d%d%d%d",&C,&N,&M,&S,&D),C;)
	{
		for(int i=0;i<=N;i++)
		{
			d[i]=INF;
			for(int j=0;j<=N;j++)
				g1[i][j]=g2[i][j]=INF;
		}
		for(int i=0;i<M;i++)
		{
			scanf("%d%d%d",&s,&t,&c);
			if(g1[s][t]>c)
			{
				g1[s][t]=g1[t][s]=c;
				g2[s][t]=g2[t][s]=c/2;
			}
		}
		d[S]=0;
		tmp.c=0;tmp.p=S;tmp.t=C;
		Q.push(tmp);
		for(;!Q.empty();)
		{
			tmp=Q.top(),Q.pop();
			for(int i=1;i<=N;i++)
			{
				int nc=tmp.c+g1[tmp.p][i];
				if((d[i]==nc&&u[i]>tmp.p)||d[i]>nc)
				{
					tmp2.c=d[i]=tmp.c+g1[tmp.p][i];
					tmp2.p=i;
					tmp2.t=tmp.t;
					Q.push(tmp2);
				}
				nc=tmp.c+g2[tmp.p][i];
				if(tmp.t>0&&((d[i]==nc&&u[i]>tmp.p-1)||d[i]>nc))
				{
					tmp2.c=d[i]=tmp.c+g2[tmp.p][i];
					tmp2.p=i;
					tmp2.t=tmp.t-1;
					Q.push(tmp2);
				}
			}
		}
		printf("%d\n",d[D]);
	}
}