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)
		}
		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)
		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<bits/stdc++.h>
#define F first
#define S second
#define INF 1<<28
using namespace std;
 
int c, n, s, d;
typedef pair < int, int > P;
typedef pair < int, P > PP;
vector < P > vec[111];
 
int solve(){
 
  int dist[111][11]; for(int i=0;i<111;i++)for(int j=0;j<11;j++) dist[i][j] = INF;
  priority_queue < PP, vector<PP>, greater<PP> > que;
 
  dist[s][c] = 0;
  que.push( PP(0, P(s, c)) ); //Now_cost, Now_node, Now_ticket
 
  while(!que.empty()){
    PP p = que.top(); que.pop();
    int cost = p.F, now = p.S.F, tic = p.S.S;
 
    //if(dist[now][tic] < cost) continue;
    for(int i=0;i<vec[now].size();i++){
      P to = vec[now][i];
      if(dist[to.S][tic] > dist[now][tic] + to.F){
	dist[to.S][tic] = dist[now][tic] + to.F;
	que.push( PP(dist[to.S][tic], P(to.S, tic)) );
      }
      if(tic && dist[to.S][tic-1] > dist[now][tic] + to.F/2){
	dist[to.S][tic-1] = dist[now][tic] + to.F/2;
	que.push( PP(dist[to.S][tic-1], P(to.S, tic-1)) );
      }
    }
  }
   
  int ans = INF;
  for(int i=0;i<=c;i++){ ans = min(ans, dist[d][i]); } //cout << ans << endl; }
  return dist[d][0];
}
 
int main(){
 
  int m, a, b, p;
 
   
  while(cin >> c >> n >> m >> s >> d){
    if((c|n|m|s|d) == 0) break;
    for(int i=0;i<111;i++) vec[i].clear();
    for(;m--;){
      cin >> a >> b >> p;
      vec[a].push_back(P(p, b)); //[now] P(cost, next);
      vec[b].push_back(P(p, a));
    }
     
    cout << solve() << endl;
  }
   
}

C++: #include <iostream>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <functional>

#define MAX 1000000000
#define Debug(X) debug( __LINE__, X )

typedef std::pair<int, int> p;

int c, n, m, s, d;
int route[101][101];
int cost[101];
std::vector<std::vector<int> > visited(101);
bool used[101];

template<class T>
void debug( int line, T dbg ){
	std::cout << line << ": " << dbg << std::endl;
}

int main(){
	while( std::cin >> c >> n >> m >> s >> d, c * n * m * s * d ){
		for( int i = 0; i < 101 * 101; ++i )
			route[i / 101][i % 101] = MAX;
		for( int i = 0; i < 101; ++i )
			cost[i] = MAX;

		memset( used, 0, sizeof( used ) );
		visited.clear();

		unsigned int tmp[3];
		while( m-- ){
			int cnt = 3;
			while( cnt-- ) std::cin >> tmp[2 - cnt];

			route[tmp[0]][tmp[1]] = tmp[2];
			route[tmp[1]][tmp[0]] = tmp[2];
		}

		cost[s] = 0;
		
		while( true ){
			unsigned pos = 0;
			for( int i = 1; i <= n; ++i ){
				if( !used[i] && (pos == 0 || cost[pos] > cost[i]) ) pos = i;
			}
			
			used[pos] = 1;
			if( pos == 0 ) break;
					
			for( int i = 1; i <= n; ++i ){
				if( i != pos ){
					std::vector<int> tmpv;
					tmpv = visited[pos];
					tmpv.push_back( route[pos][i] );
					std::sort( tmpv.begin(), tmpv.end(), std::greater<int>() );
					
					int cnt = 0;
					for( int l = 0; l < tmpv.size(); ++l ){
						if( l < c ) cnt += tmpv[l] / 2;
						else cnt += tmpv[l];
					}
					if( cnt < cost[i] ){
						cost[i] = cnt;
						visited[i] = tmpv;
					}
					
				}
			}
		}

		std::cout << cost[d] << std::endl;
	}

	return 0;
}

C++: #include<iostream>
#include<queue>
#include<map>
#define MAX 10000000
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
struct edge{
	int cost,to;
};
typedef pair<int,int> p;
typedef pair<int,p> P;
//`Pbg@»ÝÌ@v
int main(){
	int tic,n,m,s,a,b,g,d[11][101],f;
	//d ticket place
	while(cin>>tic>>n>>m>>s>>g,tic||n||m||s||g){
		s--;g--;
		//tic `Pbg
		//n Ì
		//m ´Ì
		//s¨g
		vector<edge> v[101];
		rep(i,m){
			cin>>a>>b>>f;
			a--;b--;
			edge c;
			c.cost=f;
			c.to=b;v[a].push_back(c);
			c.to=a;v[b].push_back(c);
		}
		rep(i,tic+1)
		rep(j,n){
			if(j==s)
			d[i][j]=0;
			else
			d[i][j]=MAX;
		}
		int nowticket,nowplace,nowsum;
		priority_queue<P,vector<P>,greater<P> > que;
		P now;
		que.push(P(tic,p(s,0)));
		while(!que.empty()){
			now=que.top();
			que.pop();
			nowticket=now.first;
			nowplace=now.second.first;
			nowsum=now.second.second;
			if(d[nowticket][nowplace]<nowsum)
				continue;
			rep(i,(int)v[nowplace].size()){
				edge e=v[nowplace][i];
				if(nowticket>0){
					if(d[nowticket-1][e.to]>e.cost/2+nowsum){
						d[nowticket-1][e.to]=e.cost/2+nowsum;
						que.push(P(nowticket-1,p(e.to,d[nowticket-1][e.to])));
					}
				}
				if(d[nowticket][e.to]>e.cost+nowsum){
						d[nowticket][e.to]=e.cost+nowsum;
						que.push(P(nowticket,p(e.to,d[nowticket][e.to])));
				}
			}
		}
		int mi=100000000;
		rep(i,tic+1)
		mi=min(mi,d[i][g]);
		cout<<mi<<endl;
	}
	return 0;
}

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

#define INF 1e9

using namespace std;

struct Edge {
	int to, cost;
};
struct Node {
	int now, rest, cost;
};
bool operator <(const Node& n1, const Node& n2) {
	return n1.cost < n2.cost;
}

int main() {
	int c, n, l, s, d;
	while ( cin >> c >> n >> l >> s >> d, c || n || l || s || d ) {
		--s, --d;

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

		int ans[100][11]; fill(&ans[0][0], &ans[0][0]+100*11, INF);
		priority_queue<Node> Q; Q.push( (Node){s, c, 0} );
		while ( !Q.empty() ) {
			Node node = Q.top(); Q.pop();
			if (node.cost >= ans[node.now][node.rest]) continue;
			ans[node.now][node.rest] = node.cost;

			for (int i = 0; i < m[node.now].size(); ++i) {
				Edge& e = m[node.now][i];
				if (node.cost+e.cost < ans[e.to][node.rest]) {
					Q.push( (Node){ e.to, node.rest, node.cost+e.cost } );
				}

				if (node.rest > 0) {
					if (node.cost+e.cost/2 < ans[e.to][node.rest-1]) {
						Q.push( (Node){ e.to, node.rest-1, node.cost+e.cost/2 } );
					}
				}
			}
		}
		int a = INF;
		for (int i = 0; i <= c; ++i) a = min(a, ans[d][i]);
		cout << a << endl;
	}
}