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<map>
#include<queue>
#include<vector>
using namespace std;

#define N 104
#define C 53
#define INF 1000000007
#define rep(i, n) for(int i=0; i<n; ++i)

struct Edge {
	int to, cost;
};

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

typedef vector<Edge> Graph;

Graph g[N];

int dist[N][C];
int n, c;
int dijkstra(int s, int t) {
	priority_queue<IP, vector<IP>, greater<IP> > q;
	rep(i, n) rep(j, c+1) dist[i][j] = INF;
	dist[s][0] = 0;
	q.push(IP(0, P(s, 0)));
	while(!q.empty()) {
		int cost = q.top().first, u = q.top().second.first;
		int p = q.top().second.second; q.pop();
		if(dist[u][p] < cost) continue;
		rep(i, g[u].size()) {
			Edge &e = g[u][i];
			if(dist[u][p] + e.cost < dist[e.to][p]) {
				dist[e.to][p] = dist[u][p] + e.cost;
				q.push(IP(dist[e.to][p], P(e.to, p)));
			}
			if(p < c && dist[u][p] + (e.cost / 2) < dist[e.to][p+1]) {
				dist[e.to][p+1] = dist[u][p] + (e.cost / 2);
				q.push(IP(dist[e.to][p+1], P(e.to, p+1)));
			}
		}
	}
	return dist[t][c];
}


int main() {
	int m, s, d;
	while(cin >> c >> n >> m >> s >> d && c && n && m && s && d) {
		--s; --d;
		rep(i, n) g[i].clear();
		rep(i, m) {
			int a, b, f;
			cin >> a >> b >> f; --a; --b;
			g[a].push_back((Edge){b, f});
			g[b].push_back((Edge){a, f});
		}
		cout << dijkstra(s, d) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>

const int MAX = (1<<30);

using namespace std;

int minnode;

int main(){
  int c, city, bus, from, to;
  while(cin >> c >> city >> bus >> from >> to && c && city && bus && from && to){

    int price[city+1][city+1];

    for(int i = 0; i < city+1; i++){
      for(int j = 0; j < city+1; j++){	
	price[i][j] = 0;	
      }
    }

    for(int i = 0; i < bus; i++){
      int start, end, pri;
      cin >> start >> end >> pri;

      price[start][end] = pri;
      price[end][start] = pri;
    }

    int node[city+1][c+1];
    int visited[city+1][c+1];

    for(int i = 0; i < city+1; i++){
      for(int j = 0; j < c+1; j++){	
	node[i][j] = MAX;
	visited[i][j] = 0;
      }
    }

    minnode = from;
    int ticket = c;
    node[from][c] = 0;
    int nownode = MAX;
    int minpos, mintic;
    
    while(1){
      for(int i = 1; i < city+1; i++){
	for(int j = 1; j < c+1; j++){
	  if(visited[i][j]) continue;
	  if(node[i][j] < nownode){
	    nownode = node[i][j];
	    minpos = i;
	    mintic = j;
	  }
	}
      }
      visited[minpos][mintic] = 1;
      if(nownode == MAX) break;
      
      nownode = MAX;
      
      for(int i = 1; i < city+1; i++){
	if(price[minpos][i]){
	  node[i][mintic] = min(node[i][mintic],node[minpos][mintic]+price[minpos][i]);
	  if(mintic){
	    node[i][mintic-1] = min(node[i][mintic-1],node[minpos][mintic] + price[minpos][i]/2);
	  }
	}
      }
    }

    for(int i = 1; i <= ticket; i++){
      if(node[to][0] > node[to][i]) node[to][0] = node[to][i];
    }
    cout << node[to][0] << endl;
  }
  return 0;
}

C++: // AOJ 0212 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0212)
#include <cstdio>
#include <algorithm>
#include <limits>
#include <queue>
#include <utility>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

constexpr int MAX_N = 100, INF = std::numeric_limits<int>::max()>>2;

using P = std::pair<int, std::pair<int, int>>;

struct edge
{
  int to, cost;

  edge( int to, int cost )
  : to(to), cost(cost)
  {}
};

int c, n, m, s, d;
std::vector<edge> G[MAX_N];
int dp[MAX_N][11];

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

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

    std::fill( (int*)dp, (int*)(dp+n), INF );

    std::priority_queue<P, std::vector<P>, std::greater<P>> pque;
    pque.push( P( 0, std::make_pair( s, 0 ) ) );
    dp[s][0] = 0;
    while( !pque.empty() )
    {
      P p = pque.top(); pque.pop();
      int dist = p.first, v = p.second.first, ticket = p.second.second;

      if( dist > dp[v][ticket] )
        continue;

      for( auto e : G[v] )
      {
        if( dp[e.to][ticket] > dist+e.cost )
        {
          dp[e.to][ticket] = dist+e.cost;
          pque.push( P( dp[e.to][ticket], std::make_pair( e.to, ticket ) ) );
        }
        if( ticket < 10 && dp[e.to][ticket+1] > dist+e.cost/2 )
        {
          dp[e.to][ticket+1] = dist+e.cost/2;
          pque.push( P( dp[e.to][ticket+1], std::make_pair( e.to, ticket+1 ) ) );
        }
      }
    }

    printf( "%d\n", *std::min_element( dp[d], dp[d]+c+1 ) );
  }

  return 0;
}