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 <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef pair<int, int> P;
typedef long long ll;

const int INF = 1 << 30;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

int n, m, res;

#define debug(a, b, c) for(int i = 0; i < b; i++){for(int j = 0; j < c; j++){printf("%12d", a[i][j]);}puts("");}puts("-----------------------------------------");

int main()
{
	int wk, tk, c;
	int disc, city, line, start, goal;
	int route[512][512], cost[512][16];
	bool used[512];
	while(cin >> disc >> city >> line >> start >> goal)
	{
		if(!disc && !city && !line && !start && !goal) break;

		start--, goal--;
		for(int i = 0; i < city; i++)
		{
			fill(route[i], route[i] + city, INF);
			fill(cost[i], cost[i] + city, INF);
		}

		for(int i = 0; i < line; i++)
		{
			cin >> wk >> tk >> c;
			route[wk-1][tk-1] = c;
			route[tk-1][wk-1] = c;
		}

		for(int m = 0; m <= disc; m++)
		{
			cost[start][m] = 0;
			//debug(cost, disc, city);
			fill(used, used + city, false);

			while(true)
			{
				int v = -1;
				for(int i = 0; i < city; i++)
				{
					if(!used[i] && (v == -1 || cost[i][m] < cost[v][m])) v = i;
				}

				if(v == -1) break;

				used[v] = true;

				for(int i = 0; i < city; i++)
				{
					if(m == 0)	
						cost[i][m] = min(cost[i][m], cost[v][m] + route[v][i]);
					else
						cost[i][m] = min(cost[v][m - 1] + route[v][i] / 2, min(cost[i][m], cost[v][m] + route[v][i]));
				}
			}
		}
		cout <<	cost[goal][disc] << endl;

	}
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

void shortestPath(const vector<vector<Edge> >& edges, int start, vector<int>& dist)
{
    dist.assign(edges.size(), INT_MAX);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to]){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }
}

int main()
{
    for(;;){
        int c, n, m, s, d;
        cin >> c >> n >> m >> s >> d;
        if(c == 0)
            return 0;
        -- s;
        -- d;

        vector<vector<Edge> > edges((c+1) * n);
        for(int i=0; i<m; ++i){
            int a, b, f;
            cin >> a >> b >> f;
            -- a;
            -- b;

            for(int j=0; j<=c; ++j){
                edges[a+j*n].push_back(Edge(b+j*n, f));
                edges[b+j*n].push_back(Edge(a+j*n, f));
            }
            for(int j=0; j<c; ++j){
                edges[a+j*n].push_back(Edge(b+(j+1)*n, f/2));
                edges[b+j*n].push_back(Edge(a+(j+1)*n, f/2));
            }
        }

        vector<int> dist;
        shortestPath(edges, s, dist);
        int ret = INT_MAX;
        for(int i=0; i<=c; ++i)
            ret = min(ret, dist[d+i*n]);
        cout << ret << endl;
    }
}

C++: #include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 100000
#define MAX_NODE_ID 100
#define MAX_TICKET 10
class Node{
public:
	int id;
	int cost;
	int ticket;
	Node(int i,int c,int t){
		id=i;
		cost=c;
		ticket=t;
	}
	bool operator < (const Node &o) const{
		return cost > o.cost;
	}
};
typedef priority_queue<Node> PQ;
int table[MAX_NODE_ID][MAX_NODE_ID];
bool visited[MAX_NODE_ID][MAX_TICKET];
int main(){

	for(int c,n,m,s,d;cin>>c>>n>>m>>s>>d&&(c||n||m||s||d);){
		for(int i=0;i<MAX_NODE_ID;i++)for(int j=0;j<MAX_NODE_ID;j++)table[i][j]=MAX;
		for(int i=0,a,b,f;i<m&&cin>>a>>b>>f;i++){
			table[a][b]=f;
			table[b][a]=f;
//			cout<<"table["<<a<<"]["<<b<<"]"<<table[a][b]<<endl;
//			cout<<"table["<<b<<"]["<<a<<"]"<<table[b][a]<<endl;
		}
		PQ pq;
		Node start(s,0,c);
		pq.push(start);
		while(!pq.empty()){
			int current_node=pq.top().id;
			int current_cost=pq.top().cost;
			int current_ticket=pq.top().ticket;
//			cout<<"current:"<<current_node<<endl;
			if(current_node==d)break;
			if(visited[current_node][current_ticket]);
			else{
				for(int i=1;i<=n;i++){
					if(current_node==i)continue;
					if(table[current_node][i]==MAX)continue;
	//				cout<<"["<<current_node<<"]["<<i<<"]"<<"cost:"<<table[current_node][i]<<endl;
					Node node1(i,current_cost+table[current_node][i],current_ticket);
					pq.push(node1);
					if(current_ticket>0){
						Node node2(i,current_cost+(table[current_node][i]/2),current_ticket-1);
						pq.push(node2);
					}
					visited[current_node][i]=true;
				}
			}
			pq.pop();
		}
		cout<<pq.top().cost<<endl;
	}


	return 0;
}