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<queue>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int c,n,m,s,d; while(cin>>c>>n>>m>>s>>d,c){
		s--,d--;
		int a,b,f;
		int ad[n][n],cost[c+1][n];
		rep(i,n)rep(j,n)ad[i][j]=0;
		rep(i,c+1)rep(j,n)cost[i][j]=1<<20;
		rep(i,m)cin>>a>>b>>f,a--,b--,ad[a][b]=ad[b][a]=f;
		queue<pair<int,int> > F; F.push(make_pair(c,s));
		cost[c][s]=0;
		while(!F.empty()){
			int cnode=F.front().second,cc=F.front().first; F.pop();
			rep(i,n)if(ad[cnode][i]){
				if(cost[cc][i]>cost[cc][cnode]+ad[cnode][i])
				cost[cc][i]=cost[cc][cnode]+ad[cnode][i],
				F.push(make_pair(cc,i));
				if(cc>0&&cost[cc-1][i]>cost[cc][cnode]+ad[cnode][i]/2)
				cost[cc-1][i]=cost[cc][cnode]+ad[cnode][i]/2,
				F.push(make_pair(cc-1,i));
			}
		}
		int mi,mn=1<<20;rep(i,c+1)if(cost[i][d]<mn)mi=i,mn=cost[i][d];
		cout<<mn<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <climits>
#include <vector>
using namespace std;
typedef pair<pair<int,int>,int> NODE;
#define cost first.first
#define ticket first.second 
#define pos second
#define ppp(a,b,c) make_pair(make_pair(a,b),c)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<21)

int info[100][100];
int n;

int dijk(int a,int b,int c){
	priority_queue<NODE,vector<NODE>,greater<NODE> >  Q;
	int memo[100][11];
	rep(i,100)rep(j,11)memo[i][j] = INF;
	rep(j,11)memo[a][j] = 0;
	
	Q.push(ppp(0,c,a));
	while( !Q.empty() ){
		NODE q = Q.top();Q.pop();
		for(int i=0;i<n;i++){
			if( info[q.pos][i]+q.cost < memo[i][q.ticket]){
				 memo[i][q.ticket] = info[q.pos][i]+q.cost;
				Q.push(ppp(info[q.pos][i]+q.cost ,q.ticket,i));
			}
			if( q.ticket && info[q.pos][i]/2+q.cost < memo[i][q.ticket-1] ){
					Q.push( ppp( info[q.pos][i]/2+q.cost , q.ticket-1, i));
				 memo[i][q.ticket-1] = info[q.pos][i]/2+q.cost;
			}
		}
	}
	int mi = (1<<21);
	rep(j,11)mi = min(memo[b][j],mi);
	return mi;
}
int main(){
	int c,m,s,d,a,b,f;
	while(cin >> c >> n >> m >> s >> d ,c ){
		s--;d--;
		rep(i,100)rep(j,100)info[i][j]=INF*2;
		
		for(int i=0;i<m;i++){
			cin >> a >> b >> f;
			a--;b--;
			info[a][b] = info[b][a] = f;
		}
		cout << dijk(s,d,c) << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define INF 1000000000;
#define dis first
#define mati second.first
#define sta  second.second
using namespace std;
typedef pair <int ,pair <int,int> > P;
vector <P> mp[102];
int c,n,m,start,goal;

int bit_count(int a) {
  a = (a & 0x55555555)+((a & 0xAAAAAAAA) >> 1 );
  a = (a & 0x33333333)+((a & 0xCCCCCCCC) >> 2 );
  a = (a & 0x0F0F0F0F)+((a & 0xF0F0F0F0) >> 4 );
  a = (a & 0x00FF00FF)+((a & 0xFF00FF00) >> 8 );
  a = (a & 0x0000FFFF)+((a & 0xFFFF0000) >> 16);
  return a;
}

void henkan(int n,int kai) {
  if(kai <= 10) {
    henkan(n/2,kai+1);  
  cout << n % 2 ;
  if(kai == 0) cout << endl;
  }
}

int dijkstra() {
  int flg[1<<10][102] = {},dis[1<<10][102];
  for(int j=0;j<1<<n;j++)
    for(int i=0;i<=n;i++) dis[j][i] = -INF;

  for(int j=1;j<1<<n;j++)flg[j][start] = 1;

  priority_queue <P> Q;
  P t;
  t.dis = 0, t.mati = start, t.sta = 0;
  Q.push(t);

  while(!Q.empty()) {
    t = Q.top(),Q.pop();
    if(flg[t.sta][t.mati] == 1) continue;
    flg[t.sta][t.mati] = 1;
    for(int i=0;i<mp[t.mati].size();i++){
      int ndis = mp[t.mati][i].dis;
      int nmati = mp[t.mati][i].mati;
      int nsta = t.sta | (1<<(nmati-1));
      P tt;
      if(dis[t.sta][nmati] < t.dis-ndis && flg[t.sta][nmati] == 0) {
	tt.dis = t.dis-ndis,tt.mati = nmati,tt.sta = t.sta;
	dis[t.sta][nmati] = t.dis-ndis;
	Q.push(tt);
      }
      if(bit_count(nsta)<= c&&dis[nsta][nmati]<t.dis-ndis/2 && flg[nsta][nmati]==0){
	tt.dis = t.dis - ndis/2 , tt.mati = nmati, tt.sta = nsta;
	dis[nsta][nmati] = t.dis-ndis/2;
	Q.push(tt);
      }
    }
  }

  int ans = -INF;
  for(int j=0;j<1<<n;j++)ans = max(ans,dis[j][goal]);
   
  return -ans;
}


int main() {

  while(1) {
    cin >> c >> n >> m >> start >> goal;
    if(c==0&&n==0&&m==0&&start==0&&goal==0) break;

    for(int i=0;i<=n;i++) mp[i].clear();
    for(int i=0;i<m;i++) {
      int a,b,f;
      cin >> a >> b >> f;
      P t;
      t.dis = f,  t.mati = b , t.sta = 0;
      mp[a].push_back(t);
      t.mati = a;
      mp[b].push_back(t);
    }

    cout << dijkstra() << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
struct Edge{ int to, cost; };
vector<Edge> G[101];
int dist[11][101];
const int INF = (1<<28);
int dijkstra( int s, int a ){
  priority_queue< P, vector<P>, greater<P> > q;
  for( int j=0; j<=100; j++ )
    dist[a][j] = INF;
  dist[a][s] = 0;
  q.push({ 0, s });
  while( !q.empty() ){
    int cost = q.top().first;
    int v = q.top().second;
    q.pop();
    if( dist[a][v] < cost ) continue;
    for( auto it=G[v].begin(); it!=G[v].end(); ++it ){
      int d = dist[a][v] + it->cost;
      if( a > 0 )
        d = min( d, dist[a-1][v] + it->cost/2 );
      if( dist[a][it->to] > d ){
        dist[a][it->to] = d;
        q.push({ d, it->to });
      }
    }
  }
  //for( int i=1; i<=3; i++ )
  //  cout << dist[a][i] << ' '; cout << endl;
}
int main( void ){
  while( 1 ){
    int c,n,m,s,d,a,b,f;
    cin >> c >> n >> m >> s >> d;
    if( c == 0 ) break;
    for( int i=1; i<=n; i++ ) G[i].clear();
    for( int i=0; i<m; i++ ){
      cin >> a >> b >> f;
      G[a].push_back({ b, f });
      G[b].push_back({ a, f });
    }
    for( int i=0; i<=c; i++ )
      dijkstra( s, i );
    cout << dist[c][d] << endl;
  }
}