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 <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;
}