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 pb push_back
#define fr first
#define sc second
typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
typedef vector<int> Vi;
const int INF = (1<<25);
const int MAX_V = 101;
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

struct edge {
  int to, cost;
  edge(int _to, int _cost) {
    to = _to; cost = _cost;
  }
};

int dij(int s, int c, int g) {
  priority_queue<Pip, vector<Pip>, greater<Pip> > q;

  int d[11][101];
  for(int i=0; i<11; i++) {
    for(int j=0; j<101; j++) {
      d[i][j] = INF;
    }
  }

  d[c][s] = 0;
  q.push(Pip(0, Pii(s, c)));

  int result = INF;
  while( !q.empty() ) {
    Pip p = q.top(); q.pop();
    int now_cost = p.fr;
    int v = p.sc.fr;
    int c = p.sc.sc;

    if( v == g ) {
      result = now_cost;
      break;
    }

    for(int i=0; i<G[v].size(); i++) {
      edge e = G[v][i];

      int next_cost = d[c][v] + e.cost;
      if( next_cost < d[c][e.to] ) {
	d[c][e.to] = next_cost;
      }
      if( c ) {
	next_cost = d[c][v] + e.cost/2;
	if( next_cost < d[c-1][e.to] ) {
	  d[c-1][e.to] = next_cost;
	  q.push(Pip(next_cost, Pii(e.to, c-1)));
	}
      }
    }
  }
  return result;
}

int main() {
  int c, n, m, s, g;
  while( cin >> c >> n >> m >> s >> g, c || n || m || s || g ) {
    init(n);
    s--; g--;
    for(int i=0; i<m; i++) {
      int u, v, cost;
      cin >> u >> v >> cost;
      u--; v--;
      G[u].pb(edge(v, cost));
      G[v].pb(edge(u, cost));
    }
    int ans = dij(s, c, g);
    cout << ans << endl;
  }
}

C++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cctype>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
using namespace std;
const int INF=1<<30;

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

int V;
vector<edge> G[100];
int d[11][100];
priority_queue<P, vector<P>, greater<P> > que;

void dijkstra(int s,int a){
	
	
	for(int i=0;i<V;i++)
		d[a][i]=INF;
	que.push(P(0,s));
	d[a][s]=0;
	
	while(!que.empty()){
		P p = que.top();que.pop();
		int v = p.second;
		if(d[a][v]<p.first)	continue;
		for(int i=0;i<G[v].size();i++){
			edge e = G[v][i];
			int Min = (a==0 ? d[a][v]+e.cost : min(d[a][v]+e.cost,d[a-1][v]+e.cost/2));
			if(d[a][e.to]>Min){
				d[a][e.to]=Min;
				que.push(P(d[a][e.to],e.to));
			}
		}
	}
}

int main(){
	
	int c,m,s,end;
	edge E;
	while(cin>>c>>V>>m>>s>>end,!(c==0&&V==0&&m==0&&s==0&&end==0)){
		for(int i=0;i<m;i++){
		int a,b,f;
		cin>>a>>b>>f;
		a--;
		b--;
		E.to=b;
		E.cost=f;
		G[a].push_back(E);
		E.to=a;
		G[b].push_back(E);
		}
	
	s--;
    end--;
	for(int i=0;i<=c;i++) dijkstra(s,i);
	
	cout<<d[c][end]<<endl;
	

		for(int i=0;i<100;i++)
		G[i].clear();
	}
	
}

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;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 30;
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;
LL dp[ 100 ][ 101 ];
static LL _root[ 100 ][ 100 ];

LL solve( int now, int can_use, set<int> p ) {
	if ( now == d ) {
		return 0;
	}
	p.insert( now );
	if ( dp[ can_use ][ now ] >= 0 ) {
		return dp[ can_use ][ now ];
	}
	LL res = LL_INF;
	for ( int i = 0; i < n; ++i ) {
		if ( p.count( i ) || _root[ now ][ i ] >= res ) {
			continue;
		}
		res = min( res, solve( i, can_use, p ) + _root[ now ][ i ] );
		if ( can_use ) {
			res = min( res, solve( i, can_use - 1, p ) + _root[ now ][ i ] / 2 );
		}

	}
	return dp[ can_use ][ now ] = res;
}

int main() {
	while ( ~scanf( "%d %d %d %d %d", &c, &n, &m, &s, &d ) && n && m ) {
		--s;
		--d;
		for ( int i = 0; i < n; ++i ) {
			for ( int j = 0; j < n; ++j ) {
				_root[ i ][ j ] = LL_INF;
			}
			_root[ i ][ i ] = 0;
		}
		for ( int i = 0; i < m; ++i ) {
			int a, b, f;
			scanf( "%d %d %d", &a, &b, &f );
			--a;
			--b;
			_root[ a ][ b ] = _root[ b ][ a ] = min<LL>( _root[ a ][ b ], f );
		}
		NCLR( dp );
		LL ans = solve( s, c, set<int>() );
		printf( "%lld\n", ans );
	}
	return 0;
}