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 <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef pair<Edge, int> P;

int dijkstra2(const Graph &g, int c, int s, int t) {
  int n = g.size();
  vector<Weight> dist[c+1];
  REP(i,c+1)
    dist[i].assign(n, INF);
  dist[c][s] = 0;
  priority_queue<P> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(P(Edge(-2, s, 0),c)); !Q.empty(); ) {
    Edge e = Q.top().first;
    int cc = Q.top().second;
    Q.pop();
    FOR(f,g[e.dst]) {
      if (dist[cc][f->dst] > e.weight+f->weight) {
        dist[cc][f->dst] = e.weight+f->weight;
        Q.push(P(Edge(f->src, f->dst, e.weight+f->weight),cc));
      }
      if (cc > 0 && dist[cc-1][f->dst] > e.weight+f->weight/2) {
        dist[cc-1][f->dst] = e.weight+f->weight/2;
        Q.push(P(Edge(f->src, f->dst, e.weight+f->weight/2),cc-1));
      }      
    }
  }
  int res = INF;
  REP(i,c+1) {
    res = min(dist[i][t], res);
  }
  return res;
}

int main() {
  int c,n,m,s,d;
  while(cin>>c>>n>>m>>s>>d,c) {
    s--;d--;
    Graph g(n);
    REP(i,m) {
      int a,b,f;
      cin >> a >> b >> f;
      a--;b--;
      g[a].push_back(Edge(a,b,f));
      g[b].push_back(Edge(b,a,f));
    }
    cout << dijkstra2(g,c,s,d) << endl;
  }
}

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

#define NONE -1

// c: øÌ 1`10
// n: oXªÂÈ®¬Ì 2`100
// m: oXÌHü 1`500
// s: start
// d: goal
int c, n, m, s, d;

// ÅZoHTõ - Ï
vector < vector <int> >	edges;

int search()
{
	// Å¬l
	vector < vector <int> >		D( n, vector <int>(c+1,NONE) );
	// KâÏÝÌm[h
	vector < vector <bool> >	V( n, vector <bool>(c+1,false) );

	D[s][c] = 0;

	while (1)
	{
		int u, w, minv = NONE;
		for ( int i = 0; i < n; i++ )
		{
			for ( int j = 0; j < c+1; j++ )
			{
				if ( V[i][j] == false && D[i][j] != NONE && ( minv == NONE || minv > D[i][j] ) )
				{
					minv = D[i][j];
					u = i;
					w = j;
				}
			}
		}
		if ( minv == NONE )
			break;

		V[u][w] = true;

		for ( int v = 0; v < n; v++ )
		{
			if ( edges[u][v] == NONE )
				continue;

			if ( D[v][w] == NONE )
				D[v][w] = D[u][w] + edges[u][v];
			else
				D[v][w] = min( D[v][w], D[u][w] + edges[u][v] );

			if ( w )
			{
				if ( D[v][w-1] == NONE )
					D[v][w-1] = D[u][w] + edges[u][v]/2;
				else
					D[v][w-1] = min(D[v][w-1], D[u][w] + edges[u][v]/2);
			}
		}

	}

	int minv = NONE;
	for ( int i = 0; i < c+1; i++ )
	{
		if ( D[d][i] != NONE )
		{
			if ( minv == NONE )
				minv = D[d][i];
			else
				minv = min( minv, D[d][i] );
		}
	}
	return minv;

}

int main( void )
{
	while ( cin >> c >> n >> m >> s >> d && c && n && m && s && d )
	{
		edges	=	vector < vector <int> >( 101, vector <int>(101, NONE) );
		s--;
		d--;


		// ú»
		for ( int i = 0; i < m; i++ )
		{
			// f: a-bÔÌRXg
			int a, b, f;
			cin >> a >> b >> f;

			a--;
			b--;

			edges[a][b] = f;
			edges[b][a] = f;

		}


		// Tõ
		int kotae = search();
		cout << kotae << endl;

	}

	return 0;
}