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 <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <utility>

using namespace std;

typedef pair<int, int> Pair;

int main() {
  int c, n, m, s, d, a, b, f;
  unsigned long long answer;
  vector<Pair> edges[1100];
  unsigned long long min_cost[1100];
  priority_queue<Pair, vector<Pair>, greater<Pair> > heap;
  while (true) {
    cin >> c >> n >> m >> s >> d;
    if (c == 0) {
      return 0;
    }
    for (int i = 0; i < (c + 1) * n; ++i) {
      edges[i].clear();
      min_cost[i] = -1;
    }
    for (int i = 0; i < m; ++i) {
      cin >> a >> b >> f;
      for (int ci = 0; ci <= c; ++ci) {
        edges[a - 1 + ci * n].push_back(Pair(b - 1 + ci * n, f));
        edges[b - 1 + ci * n].push_back(Pair(a - 1 + ci * n, f));
        if (ci < c) {
          edges[a - 1 + ci * n].push_back(Pair(b - 1 + ci * n + n, f / 2));
          edges[b - 1 + ci * n].push_back(Pair(a - 1 + ci * n + n, f / 2));
        }
      }
    }
    heap.push(Pair(0, s - 1));
    min_cost[s - 1] = 0;
    while (not heap.empty()) {
      int p1 = heap.top().second;
      heap.pop();
      for (size_t i = 0; i < edges[p1].size(); ++i) {
        int p2 = edges[p1][i].first;
        int len = edges[p1][i].second;
        if (min_cost[p1] + len < min_cost[p2]) {
          min_cost[p2] = min_cost[p1] + len;
          heap.push(Pair(min_cost[p2], p2));
        }
      }
    }
    answer = min_cost[d - 1];
    for (int ci = 1; ci <= c; ++ci) {
      answer = min(answer, min_cost[d - 1 + n * ci]);
    }
    cout << answer << endl;
  }
}

C++: #include<iostream>
#include<utility>
#include<vector>
#include<cstdio>
#include<queue>
#include <map>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
//int in(){int x;cin>>x;return x;}

int main ()
{
	int c,n,m,s,d;
	while(cin>>c>>n>>m>>s>>d&&c&&n&&m&&s&&d)
	{
		int ans =0;
		priority_queue < PP, vector<PP>, greater<PP> > q;
		vector< pair< int,int > > way[110];
		for(int i=0;i<m;i++)
		{
			int a,b,f;
			cin>>a>>b>>f;
			way[a].push_back(pair<int,int>(b,f));
			way[b].push_back(pair<int,int>(a,f));
		}
		pair< int , pair<int,int> > next;
		next.first=0;next.second.first=s;next.second.second=c;
		q.push(next);
		while(!q.empty())
		{
			pair< int , pair<int,int> > now=q.top();q.pop();
			if(now.second.first==d)
			{
				ans=now.first;
				break;
			}
			
			for(int i=0;i<way[now.second.first].size();i++)
			{
				next.first=now.first+way[now.second.first][i].second;
				next.second.first=way[now.second.first][i].first;
				q.push(next);
				next.first=now.first+way[now.second.first][i].second/2;
				next.second.first=way[now.second.first][i].first;
				next.second.second=now.second.second-1;
				q.push(next);
			}
			
		}
		cout<<ans<<endl;
	}
	
	
	return 0;
}

C++: #include <cstdio> 
#include <algorithm> 
#include <queue> 
 
using namespace std; 
 
const int INF   = 100000000; 
const int C_MAX = 10; 
const int N_MAX = 100; 
 
// ¬Ìîñ 
// pair<cèÌø, ¬ÌÔ> 
typedef pair<int, int> T; 
 
// n_Ìîñ 
// pair<Å¬RXg, n_Ìîñ> 
typedef pair<int, T> P; 
 
// üÍ 
int c, n, m, s, d; 
 
// »Ì¬ÜÅÌÅ¬ÌRXg 
// cost[¬ÌÔ][cèÌø] = ïp 
int cost[N_MAX][C_MAX + 1]; 
 
// ùÉÅKlªèÏÝ©Ç¤© 
bool flag[N_MAX][C_MAX + 1]; 
 
// HüÌîñ 
// line[n_][I_] = ¿à 
int line[N_MAX][N_MAX]; 
 
// DP pL[ 
typedef priority_queue<P, vector<P>, greater<P> > Q; 
Q dp_q; 
 
// _CNXg@ 
int dijkstra(){ 
     
    while(!dp_q.empty()){ 
        P  p = dp_q.top(); dp_q.pop(); 
        T &t = p.second; 
         
        // ùÉÅKlªèÏÝ©²×é 
        if(flag[t.second][t.first]) continue; 
        flag[t.second][t.first] = true; 
         
        // ÅIn_ 
        if(t.second == d){ 
            return p.first; 
        } 
         
        for(int i = 0; i < n; ++i){ 
            // øðgíÈ¢ê 
            if(cost[i][t.first] > p.first + line[t.second][i]){ 
                cost[i][t.first] = p.first + line[t.second][i]; 
                dp_q.push(P(p.first + line[t.second][i], T(t.first, i))); 
            } 
             
            // øðg¤ê 
            if(t.first > 0 && cost[i][t.first - 1] > p.first + line[t.second][i] / 2){ 
                cost[i][t.first - 1] = p.first + line[t.second][i] / 2; 
                dp_q.push(P(p.first + line[t.second][i] / 2, T(t.first - 1, i))); 
            } 
        } 
    } 
     
    return INF; 
} 
 
void solve(){ 
     
    // ú» 
    for(int i = 0; i < N_MAX; ++i){ 
        for(int j = 0; j < C_MAX + 1; ++j){ 
            cost[i][j] = INF; 
            flag[i][j] = false; 
        } 
    } 
     
    // Jnn_ 
    dp_q = Q(); 
    dp_q.push(P(0, T(c, s))); 
     
    // _CNXg@ 
    printf("%d\n", dijkstra()); 
} 
 
int main(){ 
    int a, b, f; 
     
    while(scanf("%d %d %d %d %d", &c, &n, &m, &s, &d), c > 0){ 
        --s; 
        --d; 
         
        // ú» 
        for(int i = 0; i < N_MAX; ++i){ 
            for(int j = 0; j < N_MAX; ++j){ 
                line[i][j] = INF; 
            } 
        } 
         
        for(int i = 0; i < m; ++i){ 
            scanf("%d %d %d", &a, &b, &f); 
             
            --a; 
            --b; 
             
            line[a][b] = f; 
            line[b][a] = f; 
        } 
         
        solve(); 
    } 
     
    return 0; 
}