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