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<stdio.h>
#define INF 10000000
int c,n,m,s,g;
int e[100][100];
int d[11][100];
int i,j;
bool used[11][100];

int min(int a,int b){return a<b?a:b;}

int main(){
	while(1){
		scanf("%d %d %d %d %d",&c,&n,&m,&s,&g);
		if(c==0)return 0;
		for(i=0;i<n;i++)for(j=0;j<n;j++)e[j][i]=INF;
		for(i=0;i<m;i++){
			int a,b,f;
			scanf("%d %d %d",&a,&b,&f);
			e[a-1][b-1]=f;
			e[b-1][a-1]=f;
		}
		for(i=0;i<n;i++)for(j=0;j<=c;j++){
			d[j][i]=INF;
			used[j][i]=false;
		}
		d[c][s-1]=0;
		while(1){
			int nei=-1;
			int nej;
			for(i=0;i<n;i++)for(j=0;j<=c;j++){
				if(!used[j][i]&&(nei==-1||d[j][i]<d[nej][nei])){
					nei=i;
					nej=j;
				}
			}
			if(nei==-1)break;
			used[nej][nei]=true;
			for(i=0;i<n;i++){
				d[nej][i]=min(d[nej][i],d[nej][nei]+e[nei][i]);
				if(nej>0)d[nej-1][i]=min(d[nej-1][i],d[nej][nei]+e[nei][i]/2);
			}
		}
		int ans=INF;
		for(i=0;i<=c;i++)ans=min(ans,d[i][g-1]);
		printf("%d\n",ans);
	}
}

C++: #include<iostream>
using namespace std;
const int INF = (1<<21);
int G[101][101];
int c,n,m,s,d;

int dij(){
  int D[101][11];
  bool V[101][11];
  for(int i=0;i<n;i++){
    for(int j=0;j<c+1;j++){
      D[i][j]=INF;
      V[i][j]=false;
    }
  }
  D[s][c]=0;
  while(1){
    int minv=INF,u,w;
    for(int i=0;i<n;i++){
      for(int j=0;j<c+1;j++){
	if(!V[i][j] && minv>D[i][j]){
	  minv=D[i][j];
	  u=i;
	  w=j;
	}
      }
    }
    
    V[u][w]=true;
    if(minv == INF) break;
    for(int i=0;i<n;i++){
      if(G[u][i] == INF) continue;
      D[i][w]=min(D[i][w],D[u][w]+G[u][i]);
      if( w ){
	D[i][w-1]=min(D[i][w-1],D[u][w]+G[u][i]/2);
      }
    }
  }

  int minv=INF;
  for(int i=0;i<c+1;i++){
    if(D[d][i]<minv){
      minv=D[d][i];
    }
  }

  return minv;  
}

int main(){
  
  while(cin>> c>> n>> m>> s>> d && c){
    d--;
    s--;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	G[i][j]=INF;
      }
    }
    
    for(int i=0;i<m;i++){
      int a,b,f;
      cin>> a>> b>> f;
      a--;
      b--;
      G[a][b]=G[b][a]=f;
    }
    
    cout<< dij()<< endl;
  }
}

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[101][11];
vector<Edge> edge[101];
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<101;i++)
    for(int j=0;j<11;j++)
      minCost[i][j]=INF;

  while(!que.empty()){
    P p = que.top();
    que.pop();
    
    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)));
      }
    }
  }
  int ans=INT_MAX;
  for(int i=0;i<11;i++)
    ans=min(minCost[d][i],ans);

  return minCost[d][0];
}

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<iostream>
#include<queue>
#include<string.h>
using namespace std;

const int INF = 1<<30;

struct Node{
  int use,to,weight;
  Node() {;}
  Node(int use,int to,int weight) : use(use), to(to), weight(weight) {;}
};
bool operator<(const Node &e,const Node &f) {
  return e.weight > f.weight;
}

int dist[100][100];
bool visit[100];
int dist2[100][100];

int main() {
  int c,n,m,s,d,a,b,f;
    while(cin>>c>>n>>m>>s>>d, c|n|m|s|d) {
      s--,d--;

      for(int i=0; i<100; ++i) {
	for(int j=0; j<100; ++j) {
	  dist[i][j] = INF;
	}
	visit[i] = false;
      }

      for(int i=0; i<100; ++i)
	for(int j=0; j<100; ++j)
	  dist2[i][j] = INF;

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

      priority_queue<Node> Q;
      Q.push(Node(0,s,0));
      visit[s] = true;
      while(!Q.empty()) {
	Node now = Q.top(); Q.pop();
	if(now.to == d) {
	  cout<<now.weight<<endl;
	  break;
	}

	visit[now.to] = true;
	for(int i=0; i<n; ++i) {
	  if(!visit[i] && dist[now.to][i] != INF) {
	    if(dist2[now.use+1][i]
	       > now.weight + dist[now.to][i]/2 && now.use < c) {
	      dist2[now.use+1][i] = now.weight + dist[now.to][i]/2;
	      Q.push(Node(now.use+1, i, dist2[now.use+1][i]));
	    }
	    if(dist2[now.use][i]
	       > now.weight + dist[now.to][i]) {
	      dist2[now.use][i] = now.weight + dist[now.to][i];
	      Q.push(Node(now.use, i, dist2[now.use][i]));
	    }
	  }
	}
      }
    }
}