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

struct Data{
  int id;
  int cost;
  int ticket;
};
bool operator<(Data a, Data b){
  return a.cost!=b.cost?a.cost>b.cost:(a.ticket!=b.ticket?a.ticket<b.ticket:a.id>b.id);
}
struct Data2{
  int id;
  int ticket;
};
bool operator<(Data2 a, Data2 b){
  return a.id!=b.id?a.id>b.id:a.ticket<b.ticket;
}

#define NONE INT_MAX

int Dijkstra(vector< vector<int> >A,int start,int goal,int ticket)
{
  vector<int>cost(A.size(),NONE);
  priority_queue<Data>q;
  set<Data2>used;

  Data node={start,0,ticket};
  q.push(node);
  cost[start]=0;

  while(q.size()){
    node=q.top();q.pop();
    if(node.id==goal)return node.cost;
    Data2 t={node.id,node.ticket};
    if(used.count(t))continue;
    used.insert(t);
    for(int i=0;i<A[node.id].size();i++){
      if(A[node.id][i]==NONE)continue;
      if(node.ticket){
	if(cost[i]<=cost[node.id]+(A[node.id][i])/2)continue;
	Data next={i,cost[node.id]+(A[node.id][i])/2,node.ticket-1};
	cost[i]=next.cost;
	q.push(next);
      }else{
	if(cost[i]<=cost[node.id]+A[node.id][i])continue;
	Data next={i,cost[node.id]+A[node.id][i],node.ticket};
	cost[i]=next.cost;
	q.push(next);
      }
    }
  }
  return -1;
}

int main()
{
  int c,n,m,s,d;
  int a,b,f;
  while(cin>>c>>n>>m>>s>>d,c|n|m|s|d){
    s--;d--;
    vector< vector<int> >A(n,vector<int>(n,NONE));
    for(int i=0;i<m;i++){
      cin>>a>>b>>f;
      a--;b--;
      A[a][b]=A[b][a]=f;
    }
    cout<<Dijkstra(A,s,d,c)<<endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
const int MAX_N = 110;
struct edge
{
    int to, cost, card;
    bool operator<(const edge &a) const { return cost > a.cost; }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int c, n, m, s, d;
    while (cin >> c >> n >> m >> s >> d, c | n | m)
    {
        s--, d--;
        vector<edge> G[MAX_N];
        for (int i = 0; i < m; i++)
        {
            int a, b, f;
            cin >> a >> b >> f;
            a--, b--;
            G[a].push_back({b, f, 0});
            G[b].push_back({a, f, 0});
            G[a].push_back({b, f / 2, 1});
            G[b].push_back({a, f / 2, 1});
        }
        priority_queue<edge> que;
        vector<vector<int>> dist(n, vector<int>(15, INF));
        dist[s][c] = 0;
        que.push({s, 0, c});
        while(que.size())
        {
            edge p = que.top(); que.pop();
            for(int u = 0; u < G[p.to].size(); u++)
            {
                edge e = G[p.to][u];
                int num = p. card - e.card;
                if(num < 0) continue;
                if(e.cost + dist[p.to][p.card] < dist[e.to][num])
                {
                    dist[e.to][num] = dist[p.to][p.card] + e.cost;
                    que.push({e.to, dist[e.to][num], num});
                }
            }
        }
        int ans = INF;
        for(int i = 0; i < 15; i++) ans = min(ans, dist[d][i]);
        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 100000
#define MAX_NODE_ID 100
#define MAX_TICKET 10
class Node{
public:
	int id;
	int cost;
	int ticket;
	Node(int i,int c,int t){
		id=i;
		cost=c;
		ticket=t;
	}
	bool operator < (const Node &o) const{
		return cost > o.cost;
	}
};
typedef priority_queue<Node> PQ;
int table[MAX_NODE_ID][MAX_NODE_ID];
bool visited[MAX_NODE_ID][MAX_TICKET];
int main(){

	for(int c,n,m,s,d;cin>>c>>n>>m>>s>>d&&(c||n||m||s||d);){
		for(int i=0;i<MAX_NODE_ID;i++)for(int j=0;j<MAX_NODE_ID;j++)table[i][j]=MAX;
		for(int i=0,a,b,f;i<m&&cin>>a>>b>>f;i++){
			table[a][b]=f;
			table[b][a]=f;
//			cout<<"table["<<a<<"]["<<b<<"]"<<table[a][b]<<endl;
//			cout<<"table["<<b<<"]["<<a<<"]"<<table[b][a]<<endl;
		}
		PQ pq;
		Node start(s,0,c);
		pq.push(start);
		while(!pq.empty()){
//			cout<<"current:"<<current_node<<endl;
			if(pq.top().id==d)break;
			if(visited[pq.top().id][pq.top().cost]);
			else{
				for(int i=1;i<=n;i++){
					if(pq.top().id==i)continue;
					if(table[pq.top().id][i]==MAX)continue;
	//				cout<<"["<<current_node<<"]["<<i<<"]"<<"cost:"<<table[current_node][i]<<endl;
					Node node1(i,pq.top().cost+table[pq.top().id][i],pq.top().ticket);
					pq.push(node1);
					if(pq.top().ticket>0){
						Node node2(i,pq.top().cost+(table[pq.top().id][i]/2),pq.top().ticket-1);
						pq.push(node2);
					}
					visited[pq.top().id][i]=true;
				}
			}
			pq.pop();
		}
		cout<<pq.top().cost<<endl;
	}


	return 0;
}