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<bits/stdc++.h>
using namespace std;
#define M 100000007
#define ff first.first
#define fs first.second;
typedef pair<int,int> P;
typedef pair<P,int> Pi;
int main(void){
	int c,n,m,s,d;
	while(1){
		cin>>c>>n>>m>>s>>d;
		if(n==0)break;
		vector<P> cost[n+1];
		for(int i=0;i<m;i++){
			int a,b,l;
			cin>>a>>b>>l;
			cost[a].push_back(P(b,l)); cost[b].push_back(P(a,l));
		}
		int leng[c+1][n+1];
		priority_queue<Pi> que;
		for(int i=0;i<=c;i++) fill(leng[i],leng[i]+n+1,M);
		leng[0][s]=0;
		que.push(Pi(P(0,0),s));
		while(!que.empty()){
			Pi p=que.top(); que.pop();
			int v=p.second,w=p.fs;
			if(leng[w][v]<p.ff) continue;
			for(int i=0;i<cost[v].size();i++){
				P x=cost[v][i];
				int t=leng[w][v]+x.second;
				if(leng[w][x.first]>t){
					leng[w][x.first]=t;
					que.push(Pi(P(t,w),x.first));
				}
				t-=x.second/2;
				if(w<c&&leng[w+1][x.first]>t){
					leng[w+1][x.first]=t;
					que.push(Pi(P(t,w+1),x.first));
				}
			}
		}
		cout<<leng[c][d]<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<map>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair< int ,int > P;
typedef pair< int , P > road;
main(){
  while(1){
    int c,n,m,s,d;
    int a,b,f;
    vector< P > bus[120];
    int min_cost[120];
    queue< road > que;
    road r;
    P p;
    cin>>c>>n>>m>>s>>d;//c waribiki n mati m rosen s start d goal
    if(c==0&&n==0&&m==0&&s==0&&d==0)break;
    for(int i=1;i<=n;i++){
      min_cost[i]=1<<21;
    }
    for(int i=0;i<m;i++){
      cin>>a>>b>>f;
      p.first=b;
      p.second=f;
      bus[a].push_back(p);
      p.first=a;
      p.second=f;
      bus[b].push_back(p);
    }
    r.first=c;
    r.second.first=s;
    r.second.second=0;
    que.push(r);
    while(!que.empty()){
      road now=que.front();
      //cout<<"now="<<now.first<<" "<<now.second.first<<" "<<now.second.second<<endl;
      int size=bus[now.second.first].size();
      for(int i=0;i<size;i++){
	if(bus[now.second.first][i].second+now.second.second<min_cost[bus[now.second.first][i].first]){
	  min_cost[bus[now.second.first][i].first]=bus[now.second.first][i].second+now.second.second;
	  r.first=now.first;
	  r.second.first=bus[now.second.first][i].first;
	  r.second.second=bus[now.second.first][i].second+now.second.second;
	  que.push(r);
	}
	if(now.first!=0&&bus[now.second.first][i].second/2+now.second.second<min_cost[bus[now.second.first][i].first]){
	  min_cost[bus[now.second.first][i].first]=bus[now.second.first][i].second/2+now.second.second;
	  r.first=now.first-1;
	  r.second.first=bus[now.second.first][i].first;
	  r.second.second=bus[now.second.first][i].second/2+now.second.second;
	  que.push(r); 
	}
      }  
      que.pop();
    }
    while(!que.empty()){
      que.pop();
    }
    cout<<min_cost[d]<<endl;
  }
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pp;

const int INF = 1e9;

double EPS = 1e-10;


int c, n, m, s, g;



const int MAX_V = 10000;


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


int V;
vector<edge> G[MAX_V];
map<pii, int> d;


void dijkstra(){
	priority_queue<pp, vector<pp>, greater<pp> > que;
	for(int i = 0; i <= 500000; i++){
		for(int j = 0; j <= 10; j++){
			d[mp(i, -j)] = INF;

		}
	}
	// cout<<"OK"<<endl;
	// cout<<d[mp(2, 0)]<<endl;
	d[mp(s, -c)] = 0;
	que.push(pp(0, pii(s, -c)));

	while(!que.empty()){
		pp p = que.top();
		que.pop();
		pii v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v.fi].size(); i++){
			edge e = G[v.fi][i];
			//cout<<e.to<<" "<<e.cost<<endl;
			//cout<<" "<<d[mp(e.to, v.se)]<<" "<<d[v] + e.cost<<" "<<e.to<<endl;
			if(d[mp(e.to, v.se)] > d[v] + e.cost){
				//cout<<" "<<v.fi<<" "<<d[mp(e.to, v.se)]<<endl;
				d[mp(e.to, v.se)] = d[v] + e.cost;
				que.push(pp(d[mp(e.to, v.se)],pii(e.to, v.se)));
			}
			if(v.se < 0 && d[mp(e.to, v.se + 1)] > d[v] + e.cost/2){
				//cout<<" "<<v.fi<<" "<<d[mp(e.to, v.se)]<<endl;
				d[mp(e.to, v.se + 1)] = d[v] + e.cost / 2;
				que.push(pp(d[mp(e.to, v.se + 1)],pii(e.to, v.se + 1)));
			}
		}
	}
}


int main(){
	int a, b, f;
	int ans;
	while(cin>>c>>n>>m>>s>>g){
		if(c == 0 && n == 0 && m == 0 && s == 0 && g == 0) break;
		s--; g--;
		for(int i = 0; i < MAX_V; i++) G[i].clear();
		for(int i = 0; i < m; i++){
			cin>>a>>b>>f;
			f/=10;
			a--; b--;
			G[a].push_back(edge(b, f));
			G[b].push_back(edge(a, f));
		}
		dijkstra();
		ans = INF;
		for(int i = -10; i <= 0; i++){
			ans = min(ans, d[mp(g, i)]);
		}
		//cout<<"   "<<d[mp(2,0)]<<endl;
		cout<<ans*10<<endl;
	}
	
}