Go: package main

import (
	"container/heap"
	"fmt"
)

type Node struct {
	NowPosition          int
	DiscountTicketTCount int
	Amount               int
}

type PriorityQueueNode []*Node

func (pq PriorityQueueNode) Len() int {
	return len(pq)
}

func (pq PriorityQueueNode) Less(i, j int) bool {
	return pq[i].Amount < pq[j].Amount
}

func (pq PriorityQueueNode) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueueNode) Push(node interface{}) {
	*pq = append(*pq, node.(*Node))
}

func (pq *PriorityQueueNode) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

type Point struct {
	NextPoint int
	Fee       int
}

func main() {
	var c, n, m, s, d int
	var a, b, f int

	for {
		fmt.Scan(&c, &n, &m, &s, &d)
		if c == 0 && n == 0 && m == 0 && s == 0 && d == 0 {
			break
		}
		s--
		d--
		pointMap := make([][]Point, n)
		for i := 0; i < n; i++ {
			pointMap[i] = make([]Point, 0)
		}
		for i := 0; i < m; i++ {
			fmt.Scan(&a, &b, &f)
			a--
			b--
			pointMap[a] = append(pointMap[a], Point{NextPoint: b, Fee: f})
			pointMap[b] = append(pointMap[b], Point{NextPoint: a, Fee: f})
		}
		pq := make(PriorityQueueNode, 0)
		start := Node{NowPosition: s, DiscountTicketTCount: c, Amount: 0}
		heap.Push(&pq, &start)
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				heap.Push(&pq, next)
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					heap.Push(&pq, next)
				}
			}
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define INF 1000000

int main() {
    while (true) {
        int c, n, m, s, d;
        cin >> c >> n >> m >> s >> d;
        
        if (c==0 && n==0 && m==0 && s==0 && d==0) {
            break;
        }
        
        s -= 1;
        d -= 1;
        
        vector<P> adj_list[n*(c+1)];
    
        for (int i=0; i<m; i++) {
            int ai, bi, fi;
            cin >> ai >> bi >> fi;
            ai -= 1;
            bi -= 1;
        
            for (int j=0; j<=c; j++) {
                adj_list[ai*(c+1)+j].push_back(P(bi*(c+1)+j, fi));
                adj_list[bi*(c+1)+j].push_back(P(ai*(c+1)+j, fi));
            
                if (j>0) {
                    adj_list[ai*(c+1)+j].push_back(P(bi*(c+1)+j-1, fi/2));
                    adj_list[bi*(c+1)+j].push_back(P(ai*(c+1)+j-1, fi/2));
                }
            }
        }
        
        priority_queue<P, vector<P>, greater<P>> pq;
        int dist[n*(c+1)];
        
        for (int i=0; i<n*(c+1); i++) {
            dist[i] = INF;
        }
        
        dist[s*(c+1)+c] = 0;
        pq.push(P(0, s*(c+1)+c));
        
        while (pq.size()) {
            P p = pq.top();
            pq.pop();
            
            int d = p.first;
            int v = p.second;
            
            if (dist[v]<d) {
                continue;
            }
            
            for (int i=0; i<adj_list[v].size(); i++) {
                int nv = adj_list[v][i].first;
                int w = adj_list[v][i].second;
                
                if (dist[nv]>dist[v]+w) {
                    dist[nv] = dist[v]+w;
                    pq.push(P(dist[nv], nv));
                }
            }
        }
        
        int ans = INF;
        
        for (int i=0; i<=c; i++) {
            ans = min(ans, dist[d*(c+1)+i]);
        }
        
        cout << ans << endl;
    }
}

C++: #include <bits/stdc++.h>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
typedef int Weight;
Weight INF = 1000000000;
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int src, int dest, Weight weight) {
  g[src].push_back((Edge){src, dest, weight});
}

// Dijkstra (Verified: AOJ2005)
void dijkstra(Graph &g, Array &d, int s) {
  d.assign(g.size(), INF);
  d[s] = 0;
  typedef pair<Weight,int> P;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while (!que.empty()) {
    Weight dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    REP(i, g[v].size()) {
      Edge e = g[v][i];
      if (d[e.dest] > d[v] + e.weight) {
        d[e.dest] = d[v] + e.weight;
        que.push(P(d[e.dest], e.dest));
      }
    }
  }
}

int main() {
  while(true) {
    int c,n,m,s,d;
    cin>>c>>n>>m>>s>>d;
    if(!c) break;
    --s;--d;
    Graph g(n*(c+1));
    REP(i,m) {
      int a,b,f;
      cin>>a>>b>>f;
      --a;--b;
      REP(j,c+1) {
        add_edge(g, j*n+a, j*n+b, f);
        add_edge(g, j*n+b, j*n+a, f);
      }
      REP(j,c) {
        add_edge(g, j*n+a, (j+1)*n+b, f/2);
        add_edge(g, j*n+b, (j+1)*n+a, f/2);
      }
    }
    REP(i,n) {
      REP(j,c) {
        add_edge(g, j*n+i, (j+1)*n+i, 0);
      }
    }
    Array ary;
    dijkstra(g, ary, s);
    cout<<ary[c*n+d]<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;
const int MAX_V=101;
const int MAX_E=501;
int cost[MAX_V][MAX_V];
int d[MAX_V][11];
bool used[MAX_V][11];

int main(){
    int c,n,m,s,g;
    while(cin>>c>>n>>m>>s>>g){
        if(c==0&&n==0&&m==0&&s==0&&g==0) break;
        for(int i=1; i<=n; ++i){
            for(int j=0; j<=c; ++j){
            	d[i][j]=INF;
            	used[i][j]=false;
            }
            for(int j=1; j<=n; ++j){
                cost[i][j]=INF;
                cost[j][i]=INF;
            }
        }
        for(int i=0; i<m; ++i){
            int a,b,f;
            cin >> a >> b >> f;
            cost[a][b]=f;
            cost[b][a]=f;
        }
        d[s][0]=0;
        while(true){
            int v=-1;
            int cnt=-1;
            for(int u=1; u<=n; ++u){
            	for(int i=0; i<=c; ++i){
                	if(!used[u][i]&&(v==-1||d[u][i]<d[v][cnt])) {
                		v=u;
               			cnt=i;
                	}
                }
            }
            if(v==-1) break;
            used[v][cnt]=true;
            for(int u=1; u<=n; ++u){
            	if(cnt<c) d[u][cnt+1]=min(d[u][cnt+1],d[v][cnt]+cost[v][u]/2);
            	d[u][cnt]=min(d[u][cnt],d[v][cnt]+cost[v][u]);
            }
        }
        int ans=INF;
        for(int i=1; i<=n; ++i){
        	for(int j=1; j<=c; ++j){
        		ans=min(ans,d[g][j]);
        	}
        }
        cout << ans << "\n";
    }
    return 0;
}