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++: //Solution for aoj:0212 Highway Express Bus
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
typedef pair<int, int>P;
typedef pair < P, int > PP;
#define f first
#define s second

//struct S {
//	int cost, to, num;
//	S(int c, int t, int n) : cost(c), to(t), num(n){}
//	bool operator>(const S &s) const {
//		return cost > s.cost;
//	}
//};

const int INF = 1 << 29;
int c, n, m, s, d, ans;
int tocost[1000][100];
vector<P> town[1000];
priority_queue<PP, vector<PP>, greater<PP> > pq;


void dijkstra(){
	while (!pq.empty()){
		PP a = pq.top();
		pq.pop();
		for (int i = 0; i < town[a.f.s].size(); i++){
			int tt = town[a.f.s][i].f, cc = town[a.f.s][i].s;
			if (tocost[tt][a.s] > cc + a.f.f){
				tocost[tt][a.s] = cc + a.f.f;
				pq.push({ { cc + a.f.f, tt }, a.s });
			}
			if (a.s&&tocost[tt][a.s-1] > cc/2 + a.f.f){
				tocost[tt][a.s-1] = cc/2 + a.f.f;
				pq.push({ { cc / 2 + a.f.f, tt }, a.s - 1 });
			}
		}
	}
}
	int main(){
		while (cin >> c >> n >> m >> s >> d&&c&&n&&m&&s){
			for (int i = 0; i < 1000; i++)
				fill(tocost[i], tocost[i] + 100, INF);
			tocost[s][c] = 0;
			ans = INF;
			while (pq.size())
				pq.pop();
			for (int i = 0; i < 1000; i++)
				town[i].clear();
			for (int i = 0; i < m; i++){
				int a, b, c;
				cin >> a >> b >> c;
				town[a].push_back({ b, c });
				town[b].push_back({ a, c });
			}
			pq.push({ { 0, s }, c });
			dijkstra();
			for (int i = 0; i <= c; i++)
				ans = min(ans, tocost[d][i]);
			cout << ans << endl;
		}
		return 0;
	}

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

using namespace std;

struct P {
	int from, cost, coupon;

	bool operator >(const P& p) const {
		return cost > p.cost;
	}
};

int ecost[101][101];
int ccost[101][11]; // 0:not use coupon 1:use coupon
int c, n, m, s, d;
int i;

int main() {
	while(cin >> c >> n >> m >> s >> d, c|n|m|s|d) {
		//cout << "In looping" << endl;
		fill_n((int *)ecost, 101*101, -1);
		fill_n((int *)ccost, 101*11, 1e8);
		for(i=0; i<m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			ecost[a][b] = f;
			ecost[b][a] = f;
		}
		priority_queue<P, vector<P>, greater<P>> q;
		q.push((P){s, 0, 0});
		int dcost;
		while(!q.empty()){
			P p = q.top(); q.pop();
			// goal
			if(p.from == d) {
				dcost = p.cost;
				break;
				P p2 = q.top();
				while(p.cost <= p2.cost && p.coupon <= p2.coupon){
					q.pop();
				}
				if(q.empty()) break;
				else continue;
			}
			//
			for(i=0; i<n+1; i++){ // i:to
				if(ecost[p.from][i] != -1){
					q.push((P){i, p.cost + ecost[p.from][i], p.coupon});
					if(p.coupon+1 <= c) {
						if(p.cost + ecost[p.from][i]/2 < ccost[i][p.coupon+1]){
							q.push((P){i, p.cost + ecost[p.from][i]/2, p.coupon+1});
						}
					}
					ecost[p.from][i] = -1;
					ecost[i][p.from] = -1;
				}
			}
		}
		cout << dcost << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define INF 1e+9
using namespace std;

struct edge{ int to; int cost; };
typedef pair<int,int> P;

vector<edge> graph[100];
int cost[10][100];
int V;

void dijkstra(int dijk_s,int a){
	priority_queue<P,vector<P>,greater<P> > dijk_que;
	for(int i = 0;i < V;i++) cost[a][i] = INF;
	cost[a][dijk_s] = 0;
	dijk_que.push(make_pair(0,dijk_s));
	while(!dijk_que.empty()){
		P dijk_p = dijk_que.top();
		dijk_que.pop();
		int dijk_v = dijk_p.second;
		//if(cost[a][dijk_v] < dijk_p.first) continue;
		for(int i = 0;i < graph[dijk_v].size();i++){
			edge dijk_e = graph[dijk_v][i];
			int cmin;
			if(a == 0) cmin = cost[a][dijk_v] + dijk_e.cost;
			else cmin = min(cost[a][dijk_v] + dijk_e.cost,cost[a - 1][dijk_v] + dijk_e.cost / 2);
			if(cost[a][dijk_e.to] > cmin){
				cost[a][dijk_e.to] = cmin;
				dijk_que.push(make_pair(cost[a][dijk_e.to],dijk_e.to));
			}
		}
	}
}

int main(){
	int c,m,s,d;
	while(1){
	cin >> c >> V >> m >> s >> d;
	if(c == 0) break;
	for(int i = 0;i < m;i++){
		int a,b,f;
		cin >> a >> b >> f;
		graph[a - 1].push_back({b - 1,f});
		graph[b - 1].push_back({a - 1,f});
	}
	for(int i = 0;i <= c;i++){
		dijkstra(s - 1,i);
	}
	cout << cost[c][d - 1] << endl;
	for(int i = 0;i < V;i++) graph[i].clear();
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>

const int MAX = (1<<30);

using namespace std;

int minnode;

int main(){
  int c, city, bus, from, to;
  while(cin >> c >> city >> bus >> from >> to && c && city && bus && from && to){

    int price[city+1][city+1];

    for(int i = 0; i < city+1; i++){
      for(int j = 0; j < city+1; j++){	
	price[i][j] = 0;	
      }
    }

    for(int i = 0; i < bus; i++){
      int start, end, pri;
      cin >> start >> end >> pri;

      price[start][end] = pri;
      price[end][start] = pri;
    }

    int node[city+1][c+1];
    int visited[city+1][c+1];

    for(int i = 0; i < city+1; i++){
      for(int j = 0; j < c+1; j++){	
	node[i][j] = MAX;
	visited[i][j] = 0;
      }
    }

    minnode = from;
    int ticket = c;
    node[from][c] = 0;
    int nownode = MAX;
    int minpos, mintic;
    
    while(1){
      for(int i = 1; i < city+1; i++){
	for(int j = 0; j < c+1; j++){
	  if(visited[i][j]) continue;
	  if(node[i][j] < nownode){
	    nownode = node[i][j];
	    minpos = i;
	    mintic = j;
	  }
	}
      }
      visited[minpos][mintic] = 1;
      if(nownode == MAX) break;
      
      nownode = MAX;
      
      for(int i = 1; i < city+1; i++){
	if(price[minpos][i]){
	  node[i][mintic] = min(node[i][mintic],node[minpos][mintic]+price[minpos][i]);
	  if(mintic){
	    node[i][mintic-1] = min(node[i][mintic-1],node[minpos][mintic] + price[minpos][i]/2);
	  }
	}
      }
    }

    for(int i = 1; i <= ticket; i++){
      if(node[to][0] > node[to][i]) node[to][0] = node[to][i];
    }
    cout << node[to][0] << endl;
  }
  return 0;
}