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

using namespace std;

#define INF 100000000

struct edge {
	int to, cost;
};

int main() {
	int c, n, m, s, d;
	while (cin >> c >> n >> m >> s >> d) {
		if (c == 0 && n == 0 && m == 0 && s == 0 && d == 0) {
			break;
		}
		//vector< vector<int> > ff(n+1, vector<int>(n+1, INF));
		vector<edge> ff[101];
		vector< vector<int> > ddd(n+1, vector<int>(n+1, INF));
		int a, b, f;
		for (int i = 0; i < m; i++) {
			cin >> a >> b >> f;
			edge e;
			e.to = b;
			e.cost = f;
			ff[a].push_back(e);
			e.to = a;
			ff[b].push_back(e);
			//ff[a][b] = ff[b][a] = f;
			ddd[a][b] = ddd[b][a] = f;
		}
		for (int i = 1; i <= n; i++) {
			ddd[i][i] = 0;
		}
		for (int k = 1; k <= n; k++) {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					ddd[i][j] = min(ddd[i][j], ddd[i][k]+ddd[k][j]);
				}
			}
		}
		vector< vector< vector<int> > > dp(n+1, vector< vector<int> >(n+1, vector<int>(c+1, INF)));
		for (int i = 1; i <= n; i++) {
			dp[s][i][0] = ddd[s][i];
		}
		for (int k = 1; k <= c; k++) {
			for (int p = 1; p <= n; p++) {
				dp[s][p][k] = dp[s][p][k-1];
				for (int i = 1; i <= n; i++) {
					if (dp[s][i][k-1] == INF) continue;
					for (int j = 1; j <= n; j++) {
						if (ddd[i][j] == INF) continue;
						for (int q = 0; q < ff[j].size(); q++) {
							if (ddd[ff[j][q].to][p] == INF) continue;
							if (dp[s][p][k] > dp[s][i][k-1]+ddd[i][j]+(ff[j][q].cost/2)+ddd[ff[j][q].to][p]) {
								dp[s][p][k] = dp[s][i][k-1]+ddd[i][j]+(ff[j][q].cost/2)+ddd[ff[j][q].to][p];
							}
						}/*
						for (int q = 1; q <= n; q++) {
							if (ddd[q][p] == INF) continue;
							if (ff[j][q] != INF) {
								if (dp[s][p][k] > dp[s][i][k-1]+ddd[i][j]+(ff[j][q]/2)+ddd[q][p]) {
									dp[s][p][k] = dp[s][i][k-1]+ddd[i][j]+(ff[j][q]/2)+ddd[q][p];
								}
							}
						}*/
					}
				}
			}
		}
		cout << dp[s][d][c] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <cstring>
using namespace std;

class State{
public:
  int id, rem, cost;

  State(int _id, int _rem, int _cost){
    id = _id;
    rem = _rem;
    cost = _cost;
  }

  bool operator<(const State &st)const{
    return cost > st.cost;
  }
};

int c, n, m, s, d;
bool closed[102][12];
int t[102][102];

void solve(){
  priority_queue<State> open;
  memset(closed, 0, sizeof(closed));
  open.push(State(s, c, 0));

  while(!open.empty()){
    State st = open.top(); open.pop();
    if(closed[st.id][st.rem]) continue;
    closed[st.id][st.rem] = true;

    if(st.id == d){
      cout << st.cost << endl;
      return;
    }

    for(int i = 0; i < n; i++){
      if(t[st.id][i] != -1){
        open.push(State(i, st.rem, st.cost + t[st.id][i]));
        if(st.rem > 0){
          open.push(State(i, st.rem - 1, st.cost + t[st.id][i] / 2));
        }
      }
    }
  }
}

int main(){
  while(cin >> c >> n >> m >> s >> d, c || n || m || s || d){
    s--;
    d--;

    memset(t, -1, sizeof(t));

    for(int i = 0; i < m; i++){
      int a, b, f;
      cin >> a >> b >> f;
      a--;
      b--;
      t[a][b] = t[b][a] = f;
    }

    solve();
  }
}

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 flg[110]={};
		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();
			flg[now.second.first]=0;
			if(now.second.first==d)
			{
				ans=now.first;
				break;
			}
			
			for(int i=0;i<way[now.second.first].size();i++)
			{
				if(flg[way[now.second.first][i].first]==1)continue;
				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;
}