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