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 <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>

#define rep(i,n)	for(int i = 0;i < n;i++)
#define rep2(i,n)	for(int i = 1;i <= n;i++)
#define each(i,x)	for(auto & i : x)

struct edge
{
	edge(int _s,int _t,int _cost)
	{
		s = _s;t = _t;cost = _cost;
	}
	int s;
	int t;
	int cost;
};

using namespace std;

int main()
{
	int c,n,m,s,d;
	cin >> c >> n >> m >> s >> d;
	while(c || n || m || s || d)
	{
		s--;d--;
		vector<list<edge>> town(n);
		vector<edge> eary;
		rep(i,m)
		{
			int a,b,f;
			cin >> a >> b >> f;
			a--;b--;
			town[a].push_back(edge(a,b,f));
			town[b].push_back(edge(b,a,f));
			eary.push_back(edge(a,b,f));
		}
		vector<vector<int>> cost(c+1,vector<int>(n,2000000));
		cost[0][s] = 0;
		bool flg;
		do
		{
			flg = false;
			each(e,eary)
			{
				rep(i,c+1)
				{
					if(cost[i][e.s] > cost[i][e.t] + e.cost)
					{
						cost[i][e.s] = cost[i][e.t] + e.cost;
						flg = true;
					}
					else if(cost[i][e.t] > cost[i][e.s] + e.cost)
					{
						cost[i][e.t] = cost[i][e.s] + e.cost;
						flg = true;
					}
				}
				rep(i,c)
				{
					if(cost[i+1][e.s] > cost[i][e.t] + e.cost/2)
					{
						cost[i+1][e.s] = cost[i][e.t] + e.cost/2;
						flg = true;
					}
					if(cost[i+1][e.t] > cost[i][e.s] + e.cost/2)
					{
						cost[i+1][e.t] = cost[i][e.s] + e.cost/2;
						flg = true;
					}
				}
			}
		}while(flg);
		int min = 10000000;
		rep(i,c+1)
		{
			if(cost[i][d] < min)
			{
				min = cost[i][d];
			}
		}
		cout << min << endl;
		cin >> c >> n >> m >> s >> d;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct state {
  int node;
  int ticket;
  int cost;
  state(int n, int t, int c) : node(n), ticket(t), cost(c) {}
  bool operator<(const state& s) const
  {
    return cost > s.cost;
  }
};

int main()
{
  int c, n, m, s, d;
  while (cin >> c >> n >> m >> s >> d && c != 0) {
    --s;  --d;
    vector<vector<pair<int,int> > > g(n);
    for (int i = 0; i < m; i++) {
      int a, b, f;
      cin >> a >> b >> f;
      --a;  --b;
      g[a].push_back(make_pair(b, f));
      g[b].push_back(make_pair(a, f));
    }

    priority_queue<state> q;
    q.push(state(s, c, 0));
    vector<vector<int> > city(n, vector<int>(c+1, 1000000));
    city[s][c] = 0;
    while (!q.empty()) {
      const state s = q.top();
      q.pop();
      if (s.node == d) {
        cout << s.cost << endl;
        break;
      }

      city[s.node][s.ticket] = s.cost;
      for (vector<pair<int,int> >::const_iterator it(g[s.node].begin()); it != g[s.node].end(); ++it) {
        const int next = it->first;
        const int cost = s.cost + it->second;
        if (cost < city[next][s.ticket]) {
          city[next][s.ticket] = cost;
          q.push(state(next, s.ticket, cost));
        }
        if (s.ticket > 0) {
          const int cost2 = s.cost + it->second/2;
          if (cost2 < city[next][s.ticket-1]) {
            city[next][s.ticket-1] = cost2;
            q.push(state(next, s.ticket-1, cost2));
          }
        }
      }
    }
  }
  return 0;
}

C++: // AOJ 0212
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#define rep(i,a) for( int i = 0; i != (a); ++i )

typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;

const int INF = 10000000;

int c, n, m, s, d;	
std::vector<P> G[101];
int dist[101][11];

int dijkstra()
{
	std::fill( (int*)dist, (int*)dist+101, INF );
	dist[s][0] = 0;
	std::priority_queue<PP, std::vector<PP>, std::greater<PP> > pque;
	pque.push( PP( P( s, 0 ), 0 ) );
	while( !pque.empty() )
	{
		PP p = pque.top(); pque.pop();
		int v = p.first.first, cost = p.first.second, tic = p.second;

		if( dist[v][tic] < cost )
			continue;

		rep( i, G[v].size() )
		{
			P &e = G[v][i];

			if( tic < c && dist[e.first][tic+1] > dist[v][tic]+e.second/2 )
			{
				dist[e.first][tic+1] = dist[v][tic]+e.second/2;
				pque.push( PP( P( e.first, dist[e.first][tic+1] ), tic+1 ) );
			}

			if( dist[e.first][tic] > dist[v][tic]+e.second )
			{
				dist[e.first][tic] = dist[v][tic]+e.second;
				pque.push( PP( P( e.first, dist[e.first][tic] ), tic ) );
			}
		}
	}

	return *std::min_element( dist[d], dist[d]+11 );
}

int main()
{
	while( scanf( "%d%d%d%d%d", &c, &n, &m, &s, &d ), c|n|m|s|d )
	{
		rep( i, 101 )
			G[i].clear();

		rep( i, m )
		{
			int a, b, f;
			scanf( "%d%d%d", &a, &b, &f );
			G[a].push_back( P( b, f ) );
			G[b].push_back( P( a, f ) );
		}

		printf( "%d\n", dijkstra() );
	}

	return 0;
}