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 <queue>
#include <vector>
#include <functional>

using namespace std;

const int INF = 10000000;

int city[101][101];

int solve( int s, int d, int c, int n ){
	int dist[11][101];
	int history[101];

	for( int i = 0;i < 11;i++ ){
		for( int j = 1;j < 101;j++ ){
			dist[i][j] = INF;
		}
	}

	for( int i = 1;i < 101;i++ ){
		history[i] = 0;
	}

	for( int i = 0;i < 11;i++ ) dist[i][s] = 0;

	typedef pair<int,int> data;
	typedef pair<int,data> graph;
	priority_queue<graph,vector<graph>,greater<graph> > q;

	q.push( graph( 0, data( s, c ) ) );

	while( !q.empty() ){
		graph a = q.top();
		int u = a.second.first;
		int uc = a.second.second;
		q.pop();
		history[u] = 1;

		for( int i = 1;i <= n;i++ ){

			if( history[i] ) continue;
			if( dist[uc][i] > dist[uc][u] + city[u][i] ){
				dist[uc][i] = dist[uc][u] + city[u][i];
				q.push( graph( dist[uc][i], data( i, uc ) ) );
			}

			if( uc && dist[uc - 1][i] > dist[uc][u] + city[u][i] / 2 ){
				dist[uc - 1][i] = dist[uc][u] + city[u][i] / 2;
				q.push( graph( dist[uc - 1][i], data( i, uc - 1 ) ) );
			}
		}
	}
	int answer = INF;
	for( int i = 0;i < 11;i++ ) answer = min( dist[i][d], answer );
	return answer;

}

int main(int argc, char const* argv[])
{
	int c,n,m,s,d;

	while( cin >> c >> n >> m >> s >> d && c != 0 ){
		int a,b,f;
		for( int i = 1;i < 101;i++ ){
			for( int j = 1;j < 101;j++ ){
				city[i][j] = INF * 2;
			}
		}
		for( int i = 0;i < m;i++ ){
			cin >> a >> b >> f;
			city[a][b] = f;
			city[b][a] = f;
		}

		cout << solve( s, d, c, n ) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

#define NONE -1

int c,n,m,s,d;
vector < vector <int> > P;
vector < vector <int> > E;
vector <int> R;
vector <bool> V;
int answer;

void solve( int t )
{
	if ( t == d )
	{
		sort( R.rbegin(), R.rend() );
		for ( int i = 0; i < min(c,R.size()); i++ )
		{
			R[i] /= 2;
		}
		if ( answer == -1 )
			answer = accumulate( R.begin(), R.end(), 0 );
		else
			answer = min( answer, accumulate( R.begin(), R.end(), 0 ) );
	}
	else
	{
		V[t] = true;
		for ( vector <int>::iterator it = E[t].begin(); it != E[t].end(); it++ )
		{
			if ( V[*it] == false )
			{
				R.push_back( P[t][*it] );
				solve(*it);
				R.pop_back();
			}
		}
		V[t] = false;
	}
}

int main( void )
{
	while ( cin >> c >> n >> m >> s >> d && c && n && m && s && d )
	{
		s--;
		d--;
		P = vector < vector <int> >(n+1, vector <int>(n+1,NONE));
		E = vector < vector <int> >(n+1);
		for ( int i = 0; i < m; i++ )
		{
			int a, b, f;
			cin >> a >> b >> f;
			P[a-1][b-1] = f;
			P[b-1][a-1] = f;
			E[a-1].push_back( b-1 );
			E[b-1].push_back( a-1 );
		}

		R = vector <int>();
		V = vector <bool>(n+1,false);
		answer = -1;
		solve( s );
		cout << answer << endl;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
#define MAX_V 101
using namespace std;

struct edge { 
  int to, cost;
  edge(){}
  edge(int to,int cost):to(to),cost(cost){};
};
typedef pair<int ,int> P;
const int INF = 1e+9;
int V; //ノードの数
vector<edge> Graph[MAX_V];
int min_cost[11][MAX_V];

int c,m,s,d;
void Dijkstra(int s,int chip){ // s:スタートからの最小コストをmin_costに設定
  priority_queue<P,vector< P >, greater<P> > que;
  min_cost[chip][s] = 0;
  que.push(P(0,s));
  
  while(!que.empty()){
    P p = que.top();que.pop();
    int now = p.second;
    int cost = p.first;
    if(min_cost[chip][now] < cost) continue;
    
    for(int i = 0; i < Graph[now].size(); i++){
      edge e = Graph[now][i];
      int a;
      if(chip == 0){
	a = min_cost[chip][now] + e.cost;
      }else{
	a = min(min_cost[chip][now] + e.cost, min_cost[chip-1][now] + e.cost / 2);
	if(min_cost[chip][e.to] > a){
	  min_cost[chip][e.to] = a;
	  que.push(P(min_cost[chip][e.to], e.to));
	}
      }
    }
  }
}

int main(){
  
  while(cin >> c >> V >> m >> s >> d && (c||V||m||s||d)){
    s--;
    d--;
    
    for(int i=0;i<m;i++){
      int a,b,f;
      cin>>a>>b>>f;
      a--;b--;
      Graph[a].push_back(edge(b,f));
      Graph[b].push_back(edge(a,f));
    }
    for(int i=0;i<=c;i++){
      for(int j=0;j<MAX_V;j++){
	min_cost[i][j] = INF;
      }
    }
    for(int i=0;i<=c;i++){
      Dijkstra(s,i);
    }

    cout<<min_cost[c][d]<<endl;
    
    for(int i=0;i<MAX_V;i++) Graph[i].clear();
  }
  return 0;
}

C++: // 2010/12/29 Tazoe

#include <iostream>
using namespace std;

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;

		int wgt[102][102];
		int hlf[102][102];
		for(int i=1; i<=n; i++)
			for(int j=1; j<=n; j++)
				if(i==j){
					wgt[i][j] = 0;
					hlf[i][j] = 20000;
				}
				else{
					wgt[i][j] = 20000;
					hlf[i][j] = 20000;
				}

		for(int i=0; i<m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			wgt[a][b] = f;
			wgt[b][a] = f;
			hlf[a][b] = f/2;
			hlf[b][a] = f/2;
		}

		int djk[12][102];
		bool flg[12][102];
		for(int i=1; i<=n; i++){
			djk[c][i] = wgt[s][i];
			flg[c][i] = false;
			djk[c-1][i] = hlf[s][i];
			flg[c-1][i] = false;
		}
		for(int j=c-2; j>=0; j--)
			for(int i=1; i<=n; i++){
				djk[j][i] = 20000;
				flg[j][i] = false;
			}

		while(true){
			int j_min = 11;
			int i_min = 0;
			int w_min = 2000000;
			for(int j=0; j<=c; j++)
				for(int i=1; i<=n; i++)
					if((!flg[j][i])&&(djk[j][i]<w_min)){
						j_min = j;
						i_min = i;
						w_min = djk[j][i];
					}

			flg[j_min][i_min] = true;
			if(i_min==d){
				cout << djk[j_min][i_min] << endl;
				break;
			}

			for(int i=1; i<=n; i++)
				if(!flg[j_min][i])
					if(wgt[i_min][i]!=20000)
						if(djk[j_min][i]>djk[j_min][i_min]+wgt[i_min][i])
							djk[j_min][i] = djk[j_min][i_min]+wgt[i_min][i];
			if(j_min!=0)
				for(int i=1; i<=n; i++)
					if(!flg[j_min-1][i])
						if(hlf[i_min][i]!=20000)
							if(djk[j_min-1][i]>djk[j_min][i_min]+hlf[i_min][i])
								djk[j_min-1][i] = djk[j_min][i_min]+hlf[i_min][i];
		}
	}

	return 0;
}