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 <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <bitset>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)
#define RPA(i,s,e) for(int i=s; i<=e; i++)
#define RPD(i,s,e) for(int i=s; i>=e; i--)
#define PB(a) push_back(a)
#define MP(i,s) make_pair(i,s)
#define ALL(a) (a).begin(), (a).end()
#define PRT(a) cout << (a) << endl

typedef pair<int,int> P;

struct edge { int to, cost; };

const int INF = 1000000009;
const int MAX_V = 111;
const int MAX_C = 15;
vector<edge> G[MAX_V];

int c, n, m, s, d;
int p, q, r;
int dp[MAX_C][MAX_V];

void add_edge(int from, int to, int cost) {
	edge e1 = { to, cost };
	edge e2 = { from, cost };
	G[from].PB(e1);
	G[to].PB(e2);
}

void dijkstra(int f, int t, int k) {
	REP(j,n) dp[k][j] = INF;

	priority_queue<P, vector<P>, greater<P> > que;
	que.push(MP(0, f));
	dp[k][f] = 0;

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

		int v = p.second;
		REP(i,G[v].size()) {
			edge& e = G[v][i];
			int minval = dp[k][v] + e.cost;
			if(k > 0) minval = min(minval, dp[k-1][v] + e.cost / 2);
			if(dp[k][e.to] > minval) {
				dp[k][e.to] = minval;
				que.push(P(minval, e.to));
			}
		}
	}
}

void solve() {
	RPA(i,0,c) {
		dijkstra(s, d, i);
	}
	PRT(dp[c][d]);
}

void coding() {
	while(scanf("%d%d%d%d%d", &c, &n, &m, &s, &d) != EOF) {
		if(c == 0 && n == 0 && m == 0 && s == 0 && d == 0) break;

		s--; d--;
		REP(i,n) G[i].clear();

		REP(i,m) {
			scanf("%d%d%d", &p, &q, &r);
			p--; q--;
			add_edge(p, q, r);
		}
		solve();
	}
}

//#define _LOCAL_TEST

int main() {
#ifdef _LOCAL_TEST
	freopen("a.in", "r", stdin);
#endif

	coding();

#ifdef _LOCAL_TEST
	cout << endl;
	cout << "This is local test" << endl;
	cout << "Do not forget to comment out _LOCAL_TEST" << endl;
#endif
}

C++: #include <cstdio>
#include <queue>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> _P;
typedef pair<int,_P> P;
int main() {
	int c,n,m,s,d;
	int a,b,f;
	int i;
	int cost1[100][100],cost2[100][11];
	priority_queue<P,vector<P>,greater<P> > que;
	while(scanf("%d%d%d%d%d",&c,&n,&m,&s,&d),c) {
		fill(cost1[0],cost1[0]+100*100,1<<27);
		fill(cost2[0],cost2[0]+100*11,1<<27);
		for(i=0;i<m;i++) {
			scanf("%d%d%d",&a,&b,&f);
			cost1[a-1][b-1]=cost1[b-1][a-1]=min(cost1[a-1][b-1],f);
		}
		while(!que.empty()) que.pop();
		que.push(P(0,_P(s-1,0)));
		cost2[s-1][0]=0;
		while(!que.empty()) {
			P p=que.top();que.pop();
			if(cost2[p.second.first][p.second.second]<p.first) continue;
			for(i=0;i<n;i++) {
				if((p.first+cost1[p.second.first][i])<cost2[i][p.second.second]) {
					cost2[i][p.second.second]=p.first+cost1[p.second.first][i];
					que.push(P(cost2[i][p.second.second],_P(i,p.second.second)));
				}
				if(p.second.second+1<=c&&(p.first+cost1[p.second.first][i]/2)<cost2[i][p.second.second+1]) {
					cost2[i][p.second.second+1]=p.first+cost1[p.second.first][i]/2;
					que.push(P(cost2[i][p.second.second+1],_P(i,p.second.second+1)));
				}
			}
		}
		printf("%d\n",cost2[d-1][c]);
	}
}

C++: #include <iostream>
#include <queue>
#include <cstring>
using namespace std;
int c, n, m, s, d;

int field[101][101];
int visited[11][101];

int main () {
	while (cin >> c >> n >> m >> s >> d, c || n || m || s || d) {
		memset(field, 0x3, sizeof(field));
		memset(visited, 0x3, sizeof(visited));
		for (int i = 0; i < m; i++) {
			int a, b, f;
			cin >> a >> b >> f;
			field[a][b] = field[b][a] = f / 10;
		}
		priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >, greater<pair<int, pair<int, int> > > > q;
		q.push(make_pair(0, make_pair(c, s)));
		while (!q.empty()) {
			pair<int, pair<int, int> > current = q.top();
			q.pop();
			if (current.second.second == d) {
				cout << current.first * 10 << endl;
				break;
			}
			for (int i = 1; i <= n; i++) {
				if (current.first + field[current.second.second][i] < visited[current.second.first][i]) {
					int next = current.first + field[current.second.second][i];
					q.push(make_pair(next, make_pair(current.second.first, i)));
					visited[current.second.first][i] = next;
				}
				if (current.second.first > 0 && current.first + field[current.second.second][i] / 2 < visited[current.second.first - 1][i]) {
					int next = current.first + field[current.second.second][i] / 2;
					q.push(make_pair(next, make_pair(current.second.first - 1, i)));
					visited[current.second.first - 1][i] = next;
				}
			}
		}
	}
	return 0;
}