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>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };
int c, n, m, s, d, ans;
vector<vector<PII> > v;
int dp[ 11 ][ 100 ];
bool check[ 11 ][ 100 ];

int solve( int canUseT, int now ) {
	if ( now == d ) {
		return 0;
	}
	if ( dp[ canUseT ][ now ] >= 0 ) {
		return dp[ canUseT ][ now ];
	}
	if ( check[ canUseT ][ now ] ) {
		return INF;
	}
	check[ canUseT ][ now ] = true;
	int res = INF;
	for ( int i = 0; i < v[now].size(); i++ ) {
		if ( canUseT ) {
			res = min( res, solve( canUseT - 1, v[ now ][ i ].first ) + v[ now ][ i ].second / 2 );
		}
		res = min( res, solve( canUseT, v[ now ][ i ].first ) + v[ now ][ i ].second );
	}
	return dp[ canUseT ][ now ] = res;
}

int main() {
	while ( ~scanf( "%d %d %d %d %d", &c, &n, &m, &s, &d ) && c && n && m && s && d ) {
		s--;
		d--;
		v.resize( n );
		NCLR( dp );
		CLR( check );
		for ( int i = 0; i < m; i++ ) {
			int a, b, f;
			scanf( "%d %d %d", &a, &b, &f );
			v[ a - 1 ].push_back( MP( b - 1, f ) );
			v[ b - 1 ].push_back( MP( a - 1, f ) );
		}
		ans = solve( c, s );
		printf( "%d\n", ans );
		v.clear();
	}
	return 0;
}

C++: #include <map>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
int cost[101][11];
int main(){
	int c,N,m,s,d,i,j,k,x;
	for(;scanf("%d%d%d%d%d",&c,&N,&m,&s,&d),N;){
		vector<map<int,int> >dist(N+1);
		memset(cost,99,sizeof(cost));
		for(k=0;k<m;k++){
			scanf("%d%d%d",&i,&j,&x);dist[i][j]=dist[j][i]=x;
		}
		for(i=0;i<=c;i++)cost[s][i]=0;
		for(;~c;c--){
			vector<bool>used(N+1);
			for(;;){ //dijkstra
				int m=9999999;
				for(i=1;i<=N;i++)if(!used[i]&&m>cost[i][c])m=cost[i][c];
				if(m==9999999)break;
				for(j=1;j<=N;j++)if(m==cost[j][c]){
					map<int,int>::iterator it=dist[j].begin();
					for(used[j]=1;it!=dist[j].end();it++){
						if(cost[it->first][c]>it->second+cost[j][c])cost[it->first][c]=it->second+cost[j][c];
						if(c&&cost[it->first][c-1]>it->second/2+cost[j][c])cost[it->first][c-1]=it->second/2+cost[j][c];
					}
				}
			}
		}
		printf("%d\n",cost[d][0]);
	}
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<28

using namespace std;
typedef pair<int,int> P;


struct edge
{
	int to;
	int cost;

	edge(int to,int cost) : to(to),cost(cost) {}
};

int d[11][101];
vector<edge> G[101];

void dijkstra(int s,int n,int ticket)
{
	priority_queue<P,vector<P>,greater<P> > que;
	rep(i,n) d[i][ticket] = INF;
	d[s][ticket] = 0;
	que.push(P(0,s));

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

		int v = p.second;
		if(d[v][ticket] < p.first) continue;

		rep(i,G[v].size())
		{
			edge e = G[v][i];
			int temp;

			if(ticket == 0)
			{
				temp = d[v][ticket] + e.cost;
			}
			else
			{
				temp =  min(d[v][ticket]+e.cost,d[v][ticket-1]+e.cost/2);
			}

			if(d[e.to][ticket] > temp)
			{
				d[e.to][ticket] = temp;
				que.push(P(d[e.to][ticket],e.to));
			}
		}
	}
}

int main()
{
	int c,n,m,s,t;
	while(cin >> c >> n >> m >> s >> t)
	{
		if(c == 0 && n == 0 && m == 0 && s == 0 && t == 0) break;
		
		s--;
		t--;
		rep(i,100) G[i].clear();

		rep(i,m)
		{
			int a,b,cost;
			cin >> a >> b >> cost;
			a--;
			b--;

			edge e(b,cost);
			G[a].push_back(e);

			edge e2(a,cost);
			G[b].push_back(e2);
		}
		
		rep(i,n) dijkstra(s,n,i);

		cout <<  d[t][c] << endl;
	}

	return 0;
}