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 <vector>
#include <queue>
using namespace std;

typedef pair<int,int> pr;
typedef pair<int,pr > ppr;
const int INF=2<<28;
int main() {
	// your code goes here
	int c,n,m,s,d,a,b,f;
	while(cin >> c >> n >> m >> s >> d && c!=0){
		int longs [101][11]={};
		for(int i=1;i<=100;i++)
			for(int j=0;j<=10;j++)
				longs[i][j]=INF;
		priority_queue<ppr,vector<ppr>,greater<ppr> > p;
		vector<pr> root[101];
		for(int i=0;i<m;i++){
			cin >> a>>b >> f;
			root[a].push_back(pr(b,f));
			root[b].push_back(pr(a,f));
		}
		longs[s][0]=0;
		p.push(ppr(0,pr(0,s)));
		while(!p.empty()){
			int f=p.top().first,point=p.top().second.second,t=p.top().second.first;
			p.pop();
			if(longs[point][t]!=f) continue;
			for(int i=0;i<root[point].size();i++){
				int dir=root[point][i].first;
				if(f+root[point][i].second <= longs[dir][t]){
				longs[dir][t]=f+root[point][i].second;
				p.push(ppr(longs[dir][t],pr(t,dir)));
				}
				if(t+1<=c && f+root[point][i].second/2 <= longs[dir][t+1]){
				longs[dir][t+1]=f+root[point][i].second/2;
				p.push(ppr(longs[dir][t+1],pr(t+1,dir)));
				}
			}
		}
		int minim=INF;
		for(int i=0;i<=c;i++)
		minim=min(minim,longs[d][i]);
		cout << minim<< endl;
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <vector>
#include <functional>
#include <algorithm>
#define MAX_V 100
#define INF 10000000
using namespace std;

struct edge{
  int to,cost;
};

typedef pair<int,int> P; //firstは最短経路,secondは頂点番号

vector<edge> G[MAX_V];
int vertexes,edges;
int d[MAX_V][MAX_V];

void dijkstra(int start,int tickets){
  priority_queue<P,vector<P>,greater<P> > que;
  for(int i=0;i<vertexes;i++) d[tickets][i] = INF;
  d[tickets][start] = 0;
  que.push(P(0,start));

  while(!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second; 
    if(d[tickets][v] < p.first) continue; //異なる2経路のコストで高い方は無視
    for(int i=0;i<G[v].size();i++){
      edge e = G[v][i];
      int minimum = (tickets==0 ? d[tickets][v] + e.cost: min(d[tickets][v] + e.cost, d[tickets-1][v] + e.cost/2));
      if(d[tickets][e.to] > minimum){
        d[tickets][e.to] = minimum;
        que.push( P(d[tickets][e.to],e.to) );
      }
    }
  }
}

int main(){
  int discounts,start,destination;
  while(cin >> discounts >> vertexes >> edges >> start >> destination){
    if(!discounts && !vertexes && !edges && !start && !destination) break;
    for(int i=0;i<edges;i++){
      int a,b,fee;
      cin >> a >> b >> fee;
      a--; b--;

      edge E;
      E.to = b;
      E.cost = fee;
      G[a].push_back(E);

      E.to = a;
      G[b].push_back(E);
    }
    start--; destination--;
    for(int i=0;i<=discounts;i++) dijkstra(start,i);
    cout << d[discounts][destination] << endl;
    for(int i=0;i<MAX_V;i++) G[i].clear();
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

struct edge {
    int to, cost;
};

struct state {
    int v, d, rest;
    bool operator<(const state& s)const{
        return d>s.d;
    }
};

int dijk(int s, int g, const vector<vector<edge>>& G, int c){

    vector<int> d(G.size(), 1000000000);
    d[s] = 0;

    priority_queue<state> q;
    q.push({ s, 0, c });
    
    vector<vector<bool>> vis(G.size(),vector<bool>(c+1,false));

    while (q.size()){
        state sta = q.top();
        q.pop();

        int v = sta.v;

        int rest = sta.rest;

        if (vis[v][rest]) continue;
        vis[v][rest] = true;

        if (d[v] > sta.d) continue;

        rep(i, G[v].size()){

            int to = G[v][i].to;
            int cost = G[v][i].cost;


            if (d[to] > sta.d + cost){

                d[to] = sta.d + cost;
                q.push({ to, sta.d + cost, rest});
            }

            if (d[to] > sta.d + cost / 2 && rest != 0){

                d[to] = sta.d + cost / 2;
                q.push({ to, sta.d + cost / 2, rest - 1 });
            }
        }
    }
    return d[g];
}

int main(){
    while (1){
        int c, V, E, s, d;
        cin >> c >> V >> E >> s >> d;
        if (c == 0) break;
        vector<vector<edge>> G(V);
        s--; d--;
        rep(i, E){
            int a, b, c;
            cin >> a >> b >> c;
            a--; b--;
            G[a].push_back({ b, c });
            G[b].push_back({ a, c });
        }
        cout << dijk(s, d, G, c) << endl;
    }
}

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

using namespace std;

struct Edge{
	int s,d,w,n;
	Edge(){}
	Edge(int s,int d,int w,int n=0):s(s),d(d),w(w),n(n){}
	bool operator<(const Edge& e)const{return w<e.w;}
	bool operator>(const Edge& e)const{return w>e.w;}
};

const int INFTY=1<<29;

int main()
{
	for(int c,n,m,s,d;cin>>c>>n>>m>>s>>d,c|n|m|s|d;){
		s--; d--;
		vector<vector<Edge> > g(n);
		for(int i=0;i<m;i++){
			int s,d,w; cin>>s>>d>>w;
			s--; d--;
			g[s].push_back(Edge(s,d,w));
			g[d].push_back(Edge(d,s,w));
		}
		priority_queue<Edge,vector<Edge>,greater<Edge> > pq;
		vector<vector<int> > cost(n,vector<int>(c+1,INFTY));
		pq.push(Edge(-1,s,0,0));
		while(pq.size()){
			Edge cur=pq.top(); pq.pop();
			if(cost[cur.d][cur.n]!=INFTY)
				continue;
			cost[cur.d][cur.n]=cur.w;
			for(int i=0;i<g[cur.d].size();i++){
				Edge& e=g[cur.d][i];
				pq.push(Edge(e.s,e.d,cur.w+e.w,cur.n));
				if(cur.n<c)
					pq.push(Edge(e.s,e.d,cur.w+e.w/2,cur.n+1));
			}
		}
		
		cout<<*min_element(cost[d].begin(),cost[d].end())<<endl;
	}
	
	return 0;
}