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 <queue>
#include <algorithm>
#include <vector>
#define INF 10e8 
using namespace std;

int c,n,m,s,d;

int cost[101][101];
int state[101][11];
struct node{
	int c;  //cost
	int n;	//number
	int t;	//times
	bool operator >(node b)const{
    return c > b.c;
	}
};

int dijkstra(int s,int g){
	node start;
	start.c=0,start.n=s,start.t=c;
	priority_queue<node,vector<node>,greater<node> > q;
	q.push(start);
	while(!q.empty()){
		node cur=q.top();
		q.pop();
		if(cur.n == g){
			int ans=cur.c;
			return ans;
		}
		if(state[cur.n][cur.t]<=cur.c)
			continue;
		else
			state[cur.n][cur.t]=cur.c;
		for(int i=1;i<=n;i++){
			if(cur.n== i)
				continue;
			node next;
			if(cur.t > 0){
				next.c=cur.c+(cost[cur.n][i]/2);
				next.n=i;
				next.t=cur.t-1;
				q.push(next);
			}
			next.c=cur.c+cost[cur.n][i];
			next.n=i;
			next.t=cur.t;
			q.push(next);
		}
	} 
}
int main(void){
	while(cin >> c >> n >> m >> s >> d,c|n|m|s|d){
		for(int i=1;i<=n;i++)
			for(int j=0;j<=c;j++)
				state[i][j]=INF;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				cost[i][j]=INF;
		int a,b,f;
		for(int i=0;i<m;i++){
			cin >> a >> b >> f;
			cost[a][b]=cost[b][a]=f;
		}
		int ans=dijkstra(s,d);
		cout << ans << endl;
	}
	return 0;
}

C++: // AOJ 0212
#include<cstdio>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#define rep(i,a) for( int i = 0; i != (a); ++i )

typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;

const int INF = 10000000;

int c, n, m, s, d;	
std::vector<P> G[101];
int dist[101][11];

int dijkstra()
{
	std::fill( (int*)dist, (int*)dist+101, INF );
	dist[s][0] = 0;
	std::priority_queue<PP, std::vector<PP>, std::greater<PP> > pque;
	pque.push( PP( P( s, 0 ), 0 ) );
	while( !pque.empty() )
	{
		PP p = pque.top(); pque.pop();
		int v = p.first.first, cost = p.first.second, tic = p.second;

		if( dist[v][tic] < cost )
			continue;

		rep( i, G[v].size() )
		{
			P &e = G[v][i];

			if( dist[e.first][tic] > dist[v][tic]+e.second )
			{
				dist[e.first][tic] = dist[v][tic]+e.second;
				pque.push( PP( P( e.first, dist[e.first][tic] ), tic ) );
			}
		}

		if( tic < c ) rep( i, G[v].size() )
		{
			P &e = G[v][i];

			if( dist[e.first][tic+1] > dist[v][tic]+e.second/2 )
			{
				dist[e.first][tic+1] = dist[v][tic]+e.second/2;
				pque.push( PP( P( e.first, dist[e.first][tic+1] ), tic+1 ) );
			}
		}
	}

	return *std::min_element( dist[d], dist[d]+11 );
}

int main()
{
	while( scanf( "%d%d%d%d%d", &c, &n, &m, &s, &d ), c|n|m|s|d )
	{
		rep( i, 101 )
			G[i].clear();

		rep( i, m )
		{
			int a, b, f;
			scanf( "%d%d%d", &a, &b, &f );
			G[a].push_back( P( b, f ) );
			G[b].push_back( P( a, f ) );
		}

		printf( "%d\n", dijkstra() );
	}

	return 0;
}

C++: #include<bits/stdc++.h>
#define F first
#define S second
#define INF 1<<28
using namespace std;
 
int c, n, s, d;
typedef pair < int, int > P;
typedef pair < int, P > PP;
vector < P > vec[111];
 
int solve(){
 
  int dist[111][11]; for(int i=0;i<111;i++)for(int j=0;j<11;j++) dist[i][j] = INF;
  priority_queue < PP, vector<PP>, greater<PP> > que;
 
  dist[s][c] = 0;
  que.push( PP(0, P(s, c)) ); //Now_cost, Now_node, Now_ticket
 
  while(!que.empty()){
    PP p = que.top(); que.pop();
    int cost = p.F, now = p.S.F, tic = p.S.S;
 
    //if(dist[now][tic] < cost) continue;
    for(int i=0;i<vec[now].size();i++){
      P to = vec[now][i];
      if(dist[to.S][tic] > cost + to.F){
	dist[to.S][tic] = cost + to.F;
	que.push( PP(dist[to.S][tic], P(to.S, tic)) );
      }
      if(tic && dist[to.S][tic-1] > cost + to.F/2){
	dist[to.S][tic-1] = cost + to.F/2;
	que.push( PP(dist[to.S][tic-1], P(to.S, tic-1)) );
      }
    }
  }
   
  int ans = INF;
  for(int i=0;i<=c;i++){ ans = min(ans, dist[d][i]); } //cout << ans << endl; }
  return ans;
}
 
int main(){
 
  int m, a, b, p;
 
   
  while(cin >> c >> n >> m >> s >> d){
    if((c|n|m|s|d) == 0) break;
    for(int i=0;i<111;i++) vec[i].clear();
    for(;m--;){
      cin >> a >> b >> p;
      vec[a].push_back(P(p, b)); //[now] P(cost, next);
      vec[b].push_back(P(p, a));
    }
     
    cout << solve() << endl;
  }
   
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

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

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

int n, m, res;

#define debug(a, b, c) for(int i = 0; i < b; i++){for(int j = 0; j < c; j++){printf("%12d", a[i][j]);}puts("");}puts("-----------------------------------------");

int main()
{
	int wk, tk, c;
	int disc, city, line, start, goal;
	int route[512][512], cost[512][16];
	bool used[512];
	while(cin >> disc >> city >> line >> start >> goal)
	{
		if(!disc && !city && !line && !start && !goal) break;

		start--, goal--;
		for(int i = 0; i < city; i++)
		{
			fill(route[i], route[i] + city, INF);
			fill(cost[i], cost[i] + city, INF);
		}

		for(int i = 0; i < line; i++)
		{
			cin >> wk >> tk >> c;
			route[wk-1][tk-1] = c;
			route[tk-1][wk-1] = c;
		}

		for(int m = 0; m <= disc; m++)
		{
			cost[start][m] = 0;
			//debug(cost, disc, city);
			fill(used, used + city, false);

			while(true)
			{
				int v = -1;
				for(int i = 0; i < city; i++)
				{
					if(!used[i] && (v == -1 || cost[i][m] < cost[v][m])) v = i;
				}

				if(v == -1) break;

				used[v] = true;

				for(int i = 0; i < city; i++)
				{
					if(m == 0)	
						cost[i][m] = min(cost[i][m], cost[v][m] + route[v][i]);
					else
						cost[i][m] = min(cost[v][m - 1] + route[v][i] / 2, min(cost[i][m], cost[v][m] + route[v][i]));
				}
			}
		}
		cout <<	cost[goal][disc] << endl;

	}
}