Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

const INF = 0x7FFFFFFF

var pass [][]int

func main() {
	for scanner.Scan() {
		pass = make([][]int, 200)
		for i := range pass {
			pass[i] = make([]int, 200)
		}
		buf := strings.Split(scanner.Text(), " ")
		c, _ := strconv.Atoi(buf[0])
		n, _ := strconv.Atoi(buf[1])
		m, _ := strconv.Atoi(buf[2])
		s, _ := strconv.Atoi(buf[3])
		d, _ := strconv.Atoi(buf[4])
		if c == 0 && n == 0 && m == 0 && s == 0 && d == 0 {
			break
		}
		s--
		d--
		for i := 0; i < 200; i++ {
			for j := 0; j < 200; j++ {
				pass[i][j] = INF
			}
		}
		for i := 0; i < 200; i++ {
			pass[i][i] = 0
		}
		for i := 0; i < m; i++ {
			scanner.Scan()
			buf_ := strings.Split(scanner.Text(), " ")
			a, _ := strconv.Atoi(buf_[0])
			b, _ := strconv.Atoi(buf_[1])
			f, _ := strconv.Atoi(buf_[2])
			a--
			b--
			pass[a][b] = f
			pass[b][a] = f
		}
		fmt.Println(dijkstra(s, d, c, n))
	}
}

func dijkstra(s, g, c, n int) float64 {
	d := make([][]float64, 200)
	used := make([][]bool, 200)
	for i := 0; i < 200; i++ {
		d[i] = make([]float64, 20)
		used[i] = make([]bool, 20)
	}
	for i := range d {
		for j := range d[i] {
			d[i][j] = INF
		}
	}
	d[s][c] = 0
	for {
		v := -1
		w := -1
		for u := 0; u < n; u++ {
			for i := 0; i < c+1; i++ {
				if !used[u][i] && (v == -1 || d[u][i] < d[v][w]) {
					v = u
					w = i
				}
			}
		}
		if v == -1 {
			break
		}
		used[v][w] = true
		for u := 0; u < n; u++ {
			d[u][w] = math.Min(d[u][w], d[v][w]+float64(pass[v][u]))
			if w-1 >= 0 && pass[v][u] != INF {
				d[u][w-1] = math.Min(d[u][w-1], d[v][w]+(float64(pass[v][u]/2.0)))
			}
		}
	}
	ret := float64(INF)
	for i := 0; i < c+1; i++ {
		ret = math.Min(ret, d[g][i])
	}
	return ret
}

C++: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cfloat>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define EACH( v, c ) for ( auto &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

struct Node
{
	int num, cost, tic;

	Node( int n, int c, int t ) : num( n ), cost( c ), tic( t )
	{
		return;
	}

	bool operator > ( const Node &a ) const
	{
		return a.cost < cost;
	}
};

struct Edge
{
	int to, cost;

	Edge( int t, int c ) : to( t ), cost( c )
	{
		return;
	}
};

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	while ( true )
	{
		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;

		if ( !( c | n | m | s | d ) )
		{
			break;
		}

		s--;
		d--;

		vector< vector< Edge > > G( n, vector< Edge >() );

		REP( i, 0, m )
		{
			int a, b, f;
			cin >> a >> b >> f;

			a--;
			b--;

			G[a].PB( Edge( b, f ) );
			G[b].PB( Edge( a, f ) );
		}

		VVI dist( n, VI( c + 1, INT_MAX ) );

		priority_queue< Node, vector< Node >, greater< Node > > que;
		que.push( Node( s, 0, 0 ) );

		while ( !que.empty() )
		{
			Node cur = que.top();
			que.pop();

			if ( c < cur.tic || dist[ cur.num ][ cur.tic ] <= cur.cost )
			{
				continue;
			}

			dist[ cur.num ][ cur.tic ] = cur.cost;

			REP( i, 0, G[ cur.num ].size() )
			{
				que.push( Node( G[ cur.num ][i].to, cur.cost + G[ cur.num ][i].cost, cur.tic ) );
				que.push( Node( G[ cur.num ][i].to, cur.cost + G[ cur.num ][i].cost / 2, cur.tic + 1 ) );
			}
		}

		cout << dist[d][c] << endl;
	}

	return 0;
}

C++: #include<queue>
#include<cstdio>
#include<algorithm>

#define	mp	make_pair

using namespace std;

typedef	pair<int,int>	pii;

const int inf=1<<29;
int adj[100][100],memo[100][11];
bool visited[100][11];

int main(){
	for(int c,m,n,src,dst;scanf("%d%d%d%d%d",&c,&m,&n,&src,&dst),c;){
		src--,dst--;
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)	adj[i][j]=(i==j?0:inf);
		for(int i=0;i<n;i++)for(int j=0;j<=c;j++)	memo[i][j]=inf,visited[i][j]=false;
		for(int i=0;i<m;i++){
			int a,b,fee;	scanf("%d%d%d",&a,&b,&fee);
			a--,b--;
			adj[a][b]=adj[b][a]=fee;
		}

		memo[src][0]=0;
		priority_queue< pair<int,pii> > pq;	pq.push(mp(0,mp(src,0)));
		while(!pq.empty()){
			pair<int,pii> a=pq.top();	pq.pop();
			int fee=-a.first;
			int u=a.second.first,tic=a.second.second;
			if(u==dst)	break;

			if(visited[u][tic])	continue;
			visited[u][tic]=true;

			for(int v=0;v<n;v++){
				if(visited[v][tic])	continue;
				if(fee+adj[u][v]<memo[v][tic]){
					memo[v][tic]=fee+adj[u][v];
					pq.push(mp(-memo[v][tic],mp(v,tic)));
				}
				if(tic<c && fee+adj[u][v]/2<memo[v][tic+1]){
					memo[v][tic+1]=fee+adj[u][v]/2;
					pq.push(mp(-memo[v][tic+1],mp(v,tic+1)));
				}
			}
		}

		int feemin=inf;
		for(int i=0;i<=c;i++)	feemin=min(feemin,memo[dst][i]);
		printf("%d\n",feemin);
	}

	return 0;
}

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

using namespace std;

typedef pair<int,pair<int,int> >P;

struct Edge{
  int to,cost;
  Edge(int _to, int _cost):to(_to), cost(_cost){};
};

int minCost[110][12];
vector<Edge> edge[110];
static const int INF = INT_MAX;

int c,n,m,s,d;

int dijkstra(void){
  priority_queue<P, vector<P>, greater<P> >que;
  que.push(make_pair(0,make_pair(s,c)));

  for(int i=0;i<=n;i++)
    for(int j=0;j<=n;j++)
      minCost[i][j]=INF;

  while(!que.empty()){
    P p = que.top();
    que.pop();
    
    for(int i=0;i<edge[p.second.first].size();i++){
      Edge e = edge[p.second.first][i];
      if(p.first+e.cost < minCost[e.to][p.second.second]){
	minCost[e.to][p.second.second] = p.first+e.cost;
	que.push(make_pair(p.first+e.cost,make_pair(e.to,p.second.second)));
      }
    }
    
    if(p.second.second==0)continue;
    
    for(int j=0;j<edge[p.second.first].size();j++){
      Edge e = edge[p.second.first][j];
      if(p.first+e.cost/2 < minCost[e.to][p.second.second-1]){
	minCost[e.to][p.second.second-1] = p.first+e.cost/2;
	que.push(make_pair(p.first+e.cost/2,make_pair(e.to,p.second.second-1)));
      }
    }
  }
  int ans=INT_MAX;
  for(int i=0;i<c+1;i++)
    ans=min(minCost[d][i],ans);

  return ans;
}

int main(void){
  int a,b,f;

  while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){

    for(int i=0;i<=n;i++)edge[i].clear();

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

    cout << dijkstra() << endl;
  }

  return 0;
}