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++: //04
#include<iostream>
#include<algorithm>

using namespace std;

struct edge{
  int a,b,f;
  edge(int aa,int bb,int ff){
    a=aa;
    b=bb;
    f=ff;
  }
  edge(){};
};

int main(){
  for(int c,n,m,s,ds;cin>>c>>n>>m>>s>>ds,c|n|s|m|ds;){
    edge e[500];
    for(int i=0;i<m;i++){
      int a,b,f;
      cin>>a>>b>>f;
      e[i]=edge(a,b,f);
    }
    int d[101][11];
    fill_n(d[0],101*11,1<<29);
    d[s][c]=0;
    for(int l=0;l<n;l++){
      for(int i=0;i<m;i++){
	for(int j=0;j<2;j++){
	  int s=e[i].a,t=e[i].b;
	  if(j){
	    swap(s,t);
	  }
	  for(int k=0;k<=10;k++){
	    d[t][k]=min(d[t][k],d[s][k]+e[i].f);
	    if(k){
	      d[t][k-1]=min(d[t][k-1],d[s][k]+e[i].f/2);
	    }
	  }
	}
      }
    }
    cout<<*min_element(d[ds],d[ds+1])<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>

const int MAX = (1<<30);

using namespace std;

int minnode;

int main(){
  int c, city, bus, from, to;
  while(cin >> c >> city >> bus >> from >> to && c && city && bus && from && to){

    int price[city+1][city+1];

    for(int i = 0; i < city+1; i++){
      for(int j = 0; j < city+1; j++){	
	price[i][j] = 0;	
      }
    }

    for(int i = 0; i < bus; i++){
      int start, end, pri;
      cin >> start >> end >> pri;

      price[start][end] = pri;
      price[end][start] = pri;
    }

    int node[city+1][c+1];
    int visited[city+1][c+1];

    for(int i = 0; i < city+1; i++){
      for(int j = 0; j < c+1; j++){	
	node[i][j] = MAX;
	visited[i][j] = 0;
      }
    }

    minnode = from;
    int ticket = c;
    node[from][c] = 0;
    int nownode = MAX;
    int minpos, mintic;
    
    while(1){
      for(int i = 1; i < city+1; i++){
	for(int j = 1; j < c+1; j++){
	  if(visited[i][j]) continue;
	  if(node[i][j] < nownode){
	    nownode = node[i][j];
	    minpos = i;
	    mintic = j;
	  }
	}
      }
      visited[minpos][mintic] = 1;
      if(nownode == MAX) break;
      
      nownode = MAX;
      
      for(int i = 1; i < city+1; i++){
	if(price[minpos][i]){
	  node[i][mintic] = min(node[i][mintic],node[minpos][mintic]+price[minpos][i]);
	  if(mintic){
	    node[i][mintic-1] = min(node[i][mintic-1],node[minpos][mintic] + price[minpos][i]/2);
	  }
	}
      }
    }

    for(int i = 1; i < ticket; i++){
      if(node[to][0] > node[to][i]) node[to][0] = node[to][i];
    }
    cout << node[to][0] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
typedef long long ll;
using namespace std;
const int MAX = 101;

int mindis[11][101];
bool used[11][101];
int eCost[101][101];

int main(){
	int c, n, m, s, d;
	while(cin >> c >> n >> m >> s >> d && c|n|m|s|d){
		for(int i = 0; i < 11; i++) fill(mindis[i], mindis[i]+MAX, 1<<29);
		for(int i = 0; i < 11; i++) fill(used[i], used[i]+MAX, false);
		for(int i = 0; i < MAX; i++) fill(eCost[i], eCost[i]+MAX, 1<<29);

		for(int i = 0; i < m; i++){
			int a, b, cost;
			cin >> a >> b >> cost;
			eCost[a][b] = cost;
			eCost[b][a] = cost;
		}

		mindis[0][s] = 0;

		while(1){
			//firstが使った割引チケット数、secondが頂点
			pair<int, int> v(-1, -1);
			int mostmin = 1<<29;
			for(int i = 0; i <= c; i++){
				for(int j = 1; j <= n; j++){
					if(!used[i][j] && ((v.first == -1 || v.second == -1) || mindis[i][j] < mostmin)){
						v.first = i;
						v.second = j;
						mostmin = mindis[i][j];
					}
				}
			}

			if(v.first == c && v.second == n) break;
			used[v.first][v.second] = true;


			for(int i = 1; i <= n; i++){
				if(v.first<c){
					if(mindis[v.first+1][i] > mindis[v.first][v.second]+(eCost[v.second][i]/2)){
						mindis[v.first+1][i] = mindis[v.first][v.second]+(eCost[v.second][i]/2);
					}
				}
				if(mindis[v.first][i] > mindis[v.first][v.second]+eCost[v.second][i]){
					mindis[v.first][i] = mindis[v.first][v.second]+eCost[v.second][i];
				}
			}
		}

		cout << mindis[c][d] << endl;
	}
	return 0;
}

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

using namespace std;

#define INF 1000000000
#define MAX_N 100

class CDij{
public:
	int min_c;
	vector<int> vec;
};

int n;
int c,m;
int s,d;

queue<int> q;

int cost[MAX_N+1][MAX_N+1];

CDij dp[MAX_N+1];//sからiに行くまでの最小運賃

vector<int> ans;

int main(){

	while(1){
		cin >> c >> n >> m >> s >> d;

		if(c+n+m+s+d==0) break;

		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				cost[i][j] = -1;
			}
		}

		for(int i=1;i<=n;i++){
			dp[i].min_c = INF;
			for(int j=0;j<dp[i].vec.size();j++){
				dp[i].vec.pop_back();
			}
		}

		for(int i=0;i<m;i++){
			int a,b,p;
			cin >> a >> b >>p;
			cost[a][b] = p;
			cost[b][a] = p;
		}

		q.push(s);
		dp[s].min_c = 0;
		dp[s].vec.push_back(s);

		while(!q.empty()){
			int now = q.front();
			q.pop();

			for(int i=1;i<=n;i++){
				if(cost[now][i] != -1){
					vector<int> root;
					root = dp[now].vec;
					root.push_back(i);

					vector<int> vec;

					int size = root.size()-1;

					for(int j=0;j<size;j++){
						vec.push_back( cost[root[j]][root[j+1]] );
					}
					sort(vec.begin(),vec.end(),greater<int>());

					size = vec.size();
					for(int j=0;j<min(c,size);j++){
						vec[j] /= 2;
					}

					int sum = 0;
					size = vec.size();

					for(int j=0;j<size;j++){
						sum+=vec[j];
					}

					if(sum < dp[i].min_c){
						dp[i].min_c = sum;
						dp[i].vec = root;
						q.push(i);
					}
				}
			}
	
		}

		ans.push_back(dp[d].min_c);

	}

	for(int i=0;i<ans.size();i++){
		cout << ans[i] << endl;
	}


	return 0;
}