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 <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

const int INF = 1 << 24;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

typedef unsigned long long ull;

struct Edge{
    int to, cost;
};

int C, N, M, S, D;
int cost[110][110];
int d[110][20], used[110][20];

void dijkstra(){
    REP(i, 110){
        REP(j, 20){
            d[i][j] = INF;
            used[i][j] = 0;
        }
    }

    d[S][0] = 0;

    while(1){
        int u = -1, v = -1;
        REP(i, N){
            REP(j, C){
                if(!used[i][j] && (u == -1 || d[u][v] > d[i][j])){u = i; v = j;}
            }
        }

        if(u == -1){break;}
        used[u][v] = 1;

        REP(i, N){
            d[i][v+1] = std::min(d[i][v+1], d[u][v] + cost[u][i] / 2);
            d[i][v] = std::min(d[i][v], d[u][v] + cost[u][i]);
        }
    }
}

int main(){
    while(std::cin >> C >> N >> M >> S >> D, C){
        S--; D--;

        REP(i, 110){
            REP(j, 110){
                cost[i][j] = INF;
            }
        }

        REP(i, M){
            int from, to, co;
            std::cin >> from >> to >> co;
            from--; to--;
        
            cost[from][to] = co;
            cost[to][from] = co;
        }

        dijkstra();

        int res = INF;
        REP(i, C+1){
            res = std::min(res, d[D][i]);
        }

        std::cout << res << std::endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;

struct Node{
    int townNum, fare, ticketNum;
    bool operator<(const Node &obj)const{
        if(fare != obj.fare)return fare > obj.fare;
        return false;
    }
};

int mini[100][11];

int main(){
    while(1){
        int c,n,m,s,d;
        scanf("%d %d %d %d %d",&c,&n,&m,&s,&d);
        if(c == 0 && n == 0 && m == 0 && s == 0 && d == 0)break;
        vector< vector<Node> > graph;
        graph.resize(n+1);

        for(int i=0;i<m;++i){
            int a,b,f;
            scanf("%d %d %d",&a,&b,&f);
            graph[a].push_back((Node){b,f,0});
            graph[b].push_back((Node){a,f,0});
        }

        for(int i=0;i<n;++i){
            for(int j=0;j<=c;++j){
                mini[i][j] = INT_MAX;
            }
        }
        mini[s-1][c] = 0;

        priority_queue<Node> Q;
        Q.push((Node){s,0,c});
        while(!Q.empty()){
            Node now = Q.top();
            Q.pop();
            if(now.townNum == d){
                cout << now.fare << endl;
                break;
            }
            for(int i=0;i<graph[now.townNum].size();++i){
                Node nextTown = graph[now.townNum][i];
                int newfare=now.fare+nextTown.fare;
                if(newfare < mini[nextTown.townNum-1][now.ticketNum]){
                    Q.push((Node){nextTown.townNum,newfare,now.ticketNum});
                    mini[nextTown.townNum-1][now.ticketNum] = newfare;
                }
                if(now.ticketNum > 0){
                    newfare = now.fare + nextTown.fare / 2;
                    if(newfare < mini[nextTown.townNum-1][now.ticketNum-1]){
                        Q.push((Node){nextTown.townNum,newfare,now.ticketNum-1});
                        mini[nextTown.townNum-1][now.ticketNum-1] = newfare;
                    }
                }
            }
        }
    }

    return 0;
}

C++: //Solution for aoj:0212 Highway Express Bus
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
typedef pair<int, int>P;


struct S {
	int cost, to, num, jud;
	S(int c, int t, int n, int j) : cost(c), to(t), num(n), jud(j) {}
	bool operator>(const S &s) const {
		return cost > s.cost;
	}
};

const int INF = 1 << 31;
int c, n, m, s, d, w;
int tocost[101][11];
vector<P> town[101];
priority_queue<S, vector<S>, greater<S> > pq;

void pq_set(int p, int sum, int j){
	for (int i = 0; i < town[p].size(); i++){
			pq.push(S(town[p][i].second + sum, town[p][i].first, j, 0));
			if (j)
				pq.push(S(town[p][i].second / 2 + sum, town[p][i].first, j - 1, 1));
	}
}

void dijkstra(){
	while (!pq.empty()){
		S a = pq.top();
		pq.pop();
		if (a.jud){
			if (tocost[a.to][a.num] < a.cost&&a.to!=s){
				tocost[a.to][a.num] = a.cost;
					pq_set(a.to, tocost[a.to][a.num], a.num);

			}
		}
			else{
				if (tocost[a.to][a.num] < a.cost&&a.to!=s){
					tocost[a.to][a.num] = a.cost;
					pq_set(a.to, tocost[a.to][a.num], a.num);
					
				}
			}
	}
}
	int main(){
		while (cin >> c >> n >> m >> s >> d&&c){
			for (int i = 0; i < 101; i++)
				fill(tocost[i], tocost[i] + 11, INF);
			fill(tocost[s], tocost[s] + 11, 0);
			while (pq.size())
				pq.pop();
			for (int i = 0; i < n; i++)
					town[i].erase(town[i].begin(),town[i].end());
			for (int i = 0; i < m; i++){
				int a, b, c;
				cin >> a >> b >> c;
				town[a].push_back({ b, c*-1 });
				town[b].push_back({ a, c*-1 });
			}
			pq_set(s, 0, c);
			dijkstra();
			cout << -tocost[d][0] << endl;
		}
	}

C++: #include <iostream>
#include <queue>
#include <vector>
using namespace std;

int C,N,M,S,D;

class Node
{
	public:
		
		vector<int> to,c;
};

class State
{
	public:

		int p,c,k;
		State(int P, int C, int K)
		{
			p=P; c=C; k=K;
		}

		bool operator<(const State &s) const
		{
			if(c!=s.c) return c>s.c;
			return k>s.k;
		}
};



int main()
{
	while(cin>>C>>N>>M>>S>>D, C||N||M||S||D)
	{
		int v[100][10] = {0};
		Node node[100];

		S--; D--;
		for(int i=0; i<M; i++)
		{
			int x,y,z;
			cin>>x>>y>>z;
			x--; y--;
			node[x].to.push_back(y);
			node[y].to.push_back(x);
			node[x].c.push_back(z);
			node[y].c.push_back(z);
		}

		priority_queue<State>	 q;
		q.push(State(S,0,0));
		while(!q.empty())
		{
			State t=q.top(); q.pop();
			if(t.p==D)
			{
				cout << t.c << endl;
				break;
			}

			if(v[t.p][t.k]) continue;
			v[t.p][t.k] = 1;

			for(int i=0; i<node[t.p].to.size(); i++)
			{
				q.push(State(node[t.p].to[i], t.c+node[t.p].c[i], t.k));
				if(t.k<C)
				{
					q.push(State(node[t.p].to[i], t.c+node[t.p].c[i]/2, t.k+1));
				}
			}
		}


	}
}