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 <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 10000;


class V{
public:
	int total;
	int ticket;
	int to;
};
bool operator>(const V &lh, const V &rh){
	return (lh.total > rh.total);
}


int main(){
	while(1){

		int c, n, m, s, d;
		cin >> c >> n >> m >> s >> d;
		if(!(c+n+m+s+d))break;
		n++;
		vector<vector<int> > fare(n, vector<int>(n, INF));
		rep(i, m){
			int a, b, f;
			cin >> a >> b >> f;
			fare[a][b] = fare[b][a] = f;
		}

		vector<vector<int> > best(c+1, vector<int>(n, INF));

		V start;
		start.total = 0;
		start.ticket = 0;
		start.to = s;

		priority_queue<V, vector<V>, greater<V> > q;
		q.push(start);

		while(!q.empty()){
			V p = q.top();
			q.pop();

			if(best[p.ticket][p.to] <= p.total) continue;
			best[p.ticket][p.to] = p.total;

			rep(i, n){
				if(fare[p.to][i] == INF ) continue;
				V next;
				next.total = p.total + fare[p.to][i];
				next.ticket = p.ticket;
				next.to = i;
				q.push(next);
				if(p.ticket < c){
					next.total = p.total + fare[p.to][i]/2;
					next.ticket = p.ticket+1;
					next.to = i;
					q.push(next);
				}
			}
		}

		rep(i, c){
			best[c][d] = min(best[c][d], best[i][d]);
		}

		cout << best[c][d] << endl;
	}

	return 0;
}

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

struct Edge { int from, to, cost; };
vector<Edge> edges;

int mincost[11][101];

int main() {
    int c, n, m, s, d;
    while (cin >> c >> n >> m >> s >> d, c) {
        edges.clear();
        int a, b, f;
        for (int i=0; i<m; ++i) {
            cin >> a >> b >> f;
            edges.push_back((Edge){ a, b, f });
            edges.push_back((Edge){ b, a, f });
        }
        for (int i=0; i<11; ++i) {
            for (int j=0; j<101; ++j) {
                mincost[i][j] = 10000000;
            }
        }
        mincost[0][s] = 0;
        for (int k=0; k<n; ++k) {
            for (int i=0; i<(int)edges.size(); ++i) {
                Edge &e = edges[i];
                for (int j=0; j<=c; ++j) {
                    mincost[j][e.to] = min(mincost[j][e.to], mincost[j][e.from] + e.cost);
                    if (j < c) {
                        mincost[j+1][e.to] = min(mincost[j+1][e.to], mincost[j][e.from] + e.cost / 2);
                    }
                }
            }
        }
        int res = 10000000;
        for (int i=0; i<10; ++i) {
            res = min(res, mincost[i][d]);
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<climits>

using namespace std;

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

struct Edge{
  int to,cost;
  Edge(int _to, int _cost):to(_to), cost(_cost){};
};

int minCost[102][12];
vector<Edge> edge[102];
static const int INF = INT_MAX;

int c,n,m,s,d;

int dijkstra(void){
  priority_queue<P, vector<P>, greater<P> >que;
  que.push(make_pair(0,make_pair(s,c)));

  for(int i=0;i<=n;i++)
    for(int j=0;j<=n;j++)
      minCost[i][j]=INF;

  while(!que.empty()){
    P p = que.top();
    que.pop();

    if(p.second.first==d)return p.first;
    
    for(int i=0;i<edge[p.second.first].size();i++){
      Edge e = edge[p.second.first][i];
      if(p.first+e.cost < minCost[e.to][p.second.second]){
	minCost[e.to][p.second.second] = p.first+e.cost;
	que.push(make_pair(p.first+e.cost,make_pair(e.to,p.second.second)));
      }
    }
    
    if(p.second.second==0)continue;
    
    for(int j=0;j<edge[p.second.first].size();j++){
      Edge e = edge[p.second.first][j];
      if(p.first+e.cost/2 < minCost[e.to][p.second.second-1]){
	minCost[e.to][p.second.second-1] = p.first+e.cost/2;
	que.push(make_pair(p.first+e.cost/2,make_pair(e.to,p.second.second-1)));
      }
    }
  }
  return -1;
}

int main(void){
  int a,b,f;

  while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){

    for(int i=0;i<=n;i++)edge[i].clear();

    for(int i=0;i<m;i++){
      cin >> a >> b >> f;
      edge[a].push_back(Edge(b,f));
      edge[b].push_back(Edge(a,f));
    }

    cout << dijkstra() << endl;
  }

  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<utility>
#include<queue>
#include<algorithm>
using namespace std;
#define INF 100000000
int C,N,M,S,D,g1[101][101],g2[101][101],s,t,c,d[101],u[101];
typedef struct P{int p,c,t;}P;
struct Order
{
	bool operator ()(P const& a, P const& b) const
	{
		return a.c==b.c?a.t<b.t:a.c>b.c;
	}
};

P tmp,tmp2;
priority_queue<P,vector<P>,Order>Q;
int main()
{
	for(;scanf("%d%d%d%d%d",&C,&N,&M,&S,&D),C;)
	{
		for(int i=0;i<=N;i++)
		{
			d[i]=INF;
			for(int j=0;j<=N;j++)
				g1[i][j]=g2[i][j]=INF;
		}
		for(int i=0;i<M;i++)
		{
			scanf("%d%d%d",&s,&t,&c);
			if(g1[s][t]>c)
			{
				g1[s][t]=g1[t][s]=c;
				g2[s][t]=g2[t][s]=c/2;
			}
		}
		d[S]=0;
		tmp.c=0;tmp.p=S;tmp.t=C;
		Q.push(tmp);
		for(;!Q.empty();)
		{
			tmp=Q.top(),Q.pop();
			for(int i=1;i<=N;i++)
			{
				int nc=tmp.c+g1[tmp.p][i];
				if((d[i]==nc&&u[i]>tmp.p)||d[i]>nc)
				{
					tmp2.c=d[i]=tmp.c+g1[tmp.p][i];
					tmp2.p=i;
					tmp2.t=tmp.t;
					Q.push(tmp2);
				}
				nc=tmp.c+g2[tmp.p][i];
				if(tmp.t>0&&((d[i]==nc&&u[i]>tmp.p-1)||d[i]>nc))
				{
					tmp2.c=d[i]=tmp.c+g2[tmp.p][i];
					tmp2.p=i;
					tmp2.t=tmp.t-1;
					Q.push(tmp2);
				}
			}
		}
		printf("%d\n",d[D]);
	}
}