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 <map>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
int cost[101][11];
int main(){
	int c,N,m,s,d,i,j,k,x;
	for(;scanf("%d%d%d%d%d",&c,&N,&m,&s,&d),N;){
		vector<map<int,int> >dist(N+1);
		memset(cost,99,sizeof(cost));
		for(k=0;k<m;k++){
			scanf("%d%d%d",&i,&j,&x);dist[i][j]=dist[j][i]=x;
		}
		for(i=0;i<=c;i++)cost[s][i]=0;
		for(;~c;c--){
			vector<bool>used(N+1);
			for(;;){ //dijkstra
				int m=1e9;
				for(i=1;i<=N;i++)if(!used[i]&&m>cost[i][c])m=cost[i][c];
				if(m==1e9)break;
				for(j=1;j<=N;j++)if(m==cost[j][c]){
					map<int,int>::iterator it=dist[j].begin();
					for(used[j]=1;it!=dist[j].end();it++){
						if(cost[it->first][c]>it->second+cost[j][c])cost[it->first][c]=it->second+cost[j][c];
						if(c&&cost[it->first][c-1]>it->second/2+cost[j][c])cost[it->first][c-1]=it->second/2+cost[j][c];
					}
				}
			}
		}
		printf("%d\n",cost[d][0]);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct line {
    ll a, b, f;
};
using pllll = pair<ll, ll>;
using pl6 = pair<ll, pair<ll, ll>>;
struct edge {
    ll dstb, dstc, cost;
};
int main() {
    
    ll c, n, m, s, d;
    while (cin >> c >> n >> m >> s >> d, c) {

        s--; d--;

        vector<line> l(m, line{0, 0, 0});
        for (ll i = 0; i < m; i++) {
            cin >> l[i].a >> l[i].b >> l[i].f;
            l[i].a--; l[i].b--;
            if (l[i].a > l[i].b) swap(l[i].a, l[i].b);
        }

        sort(l.begin(), l.end(), [](line &i, line &j) -> bool {
                 if (i.a != j.a) return i.a < j.a;
            else if (i.b != j.b) return i.b < j.b;
            else return i.f < j.f;
        });

        // 被った路線はなかったことに
        for (ll i = m; --i; ) {
            if (l[i].a == l[i-1].a && l[i].b == l[i-1].b) {
                l.erase(l.begin() + i);
            }
        }
        m = l.size();

        
        // 無向グラフを構築
        vector<vector<vector<edge>>> g(n, vector<vector<edge>>(c+1));
        for (ll i = m; i--; ) {
            ll a = l[i].a;
            ll b = l[i].b;
            ll f = l[i].f;
            for (ll c0 = c; c0 >= 0; c0--) {
                g[a][c0].push_back(edge{b, c0, f});
                g[b][c0].push_back(edge{a, c0, f});
                if (c0 > 0) {
                    g[a][c0].push_back(edge{b, c0-1, f/2});
                    g[b][c0].push_back(edge{a, c0-1, f/2});
                }
            }
        }

        // 拡張Dijkstra
        vector<vector<ll>> dp(n, vector<ll>(c+1, 0x7FFFFFFFLL));
        vector<vector<bool>> determined(n, vector<bool>(c+1, false));
        priority_queue<pl6, vector<pl6>, greater<pl6>> q;
        q.push(pl6(0, pllll(s, c)));
        dp[s][c] = 0;
        while (!q.empty()) {
            pl6 cv = q.top(); q.pop();
            pllll v = cv.second;
            ll vf = dp[v.first][v.second];
            if (determined[v.first][v.second]) continue;
            determined[v.first][v.second] = true;
            for (edge &ed : g[v.first][v.second]) {
                if (determined[ed.dstb][ed.dstc]) continue;
                if (vf + ed.cost < dp[ed.dstb][ed.dstc]) {
                    q.push(pl6(vf + ed.cost, pllll(ed.dstb, ed.dstc)));
                    dp[ed.dstb][ed.dstc] = vf + ed.cost;
                }
            }
        }

        ll ans = 0x7FFFFFFFLL;
        for (ll i = 0; i <= c; i++) {
            ans = min(ans, dp[d][i]);
        }
        cout << ans << endl;

    }

}

C++: #include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <utility>
#include <functional>
using namespace std;

#define INF 19980725

/** 割引券の枚数 */
static int c;
#define C 10
/** 町の数 */
static int n;
#define N 100
/** 路線数 */
static int m;
#define M 500
/** 出発地 */
static int s;
/** 目的地 */
static int d;

/** 路線情報 */
static int map[ N ][ N ];

/** 各探索先における状態 */
struct stat
{
  /** 到達先の町 */
  int pos;
  /** 現時点までの費用 */
  int cost;
  /** 割引券の残枚数 */
  int rem;

  stat (
    )
  {
    this->cost = INF;
    this->rem  = 0;
  }
  stat (
    int pos,
    int cost,
    int rem
    )
  {
    this->pos  = pos;
    this->cost = cost;
    this->rem  = rem;
  }
  bool operator> (
    const stat &a
    )
  const
  {
    return ( cost > a.cost
          || ( cost == a.cost && rem < a.rem ) );
  }
};

int
main (
  int   argc,
  char *argv[ ]
  )
{
  for ( ; ; )
  {
    /** 探索キュー */
    priority_queue<stat, vector<stat>, greater<stat> > lis;
    /** s->k への最小費用res[ k ] */
    int res[ N ];
    int i, j;

    /* 基本情報読み込み */
    scanf ( "%d%d%d%d%d", &c, &n, &m, &s, &d );
    if ( !( c | n | m | s | d ) ) break ;
    --s; --d;

    /* 路線情報初期化 */
    for ( i = 0; i < n; ++i )
    for ( j = 0; j < n; ++j )
      map[ i ][ j ] = INF;

    /* 路線情報読み込み */
    for ( i = 0; i < m; ++i )
    {
      int a, b, f;

      scanf ( "%d%d%d", &a, &b, &f );
      --a; --b;
      map[ a ][ b ] =
      map[ b ][ a ] = f;
    }

    /* s->d に対してダイクストラ法を適用 */
    fill ( res, res + n, INF );
    lis.push ( stat ( s, 0, c ) );
    while ( !lis.empty ( ) )
    {
      const stat st = lis.top ( );
      lis.pop ( );

      /* 結果が既に求まっていれば処理しない */
      if ( res[ st.pos ] != INF )
        continue ;
      res[ st.pos ] = st.cost;

      for ( i = 0; i < n; ++i )
      {
        /* st.pos からi への経路が存在しなければ処理しない */
        if ( map[ st.pos ][ i ] == INF )
          continue ;

        /* 隣接する町の探索を予約する．割引券が使えればその探索も予約する． */
        lis.push ( stat ( i, st.cost + map[ st.pos ][ i ], st.rem ) );
        if ( st.rem > 0 )
          lis.push ( stat ( i, st.cost + map[ st.pos ][ i ] / 2, st.rem - 1 ) );
      }
    }
    printf ( "%d\n", res[ d ] );
  }

  return ( EXIT_SUCCESS );
}