Go: package main

import (
	"container/heap"
	"fmt"
	"runtime"
)

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
}

type Memo struct {
	NowPoint             int
	DiscountTicketTCount 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, n)
		}
		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, m)
		start := Node{NowPosition: s, DiscountTicketTCount: c, Amount: 0}
		heap.Push(&pq, &start)
		memo := make(map[Memo]struct{})
		for len(pq) != 0 {
			now := heap.Pop(&pq).(*Node)
			if now.NowPosition == d {
				fmt.Println(now.Amount)
				break
			}
			memo[Memo{NowPoint: now.NowPosition, DiscountTicketTCount: now.DiscountTicketTCount}] = struct{}{}
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if _, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok {
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if _, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok {
						heap.Push(&pq, next)
					}
				}
			}
		}
		runtime.GC()
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

char c[ 6 ][ 5 ] = {
	{ 'a', 'b', 'c', 'd', 'e' },
	{ 'f', 'g', 'h', 'i', 'j' },
	{ 'k', 'l', 'm', 'n', 'o' },
	{ 'p', 'q', 'r', 's', 't' },
	{ 'u', 'v', 'w', 'x', 'y' },
	{ 'z', '.', '?', '!', ' ' },
};

int main() {
	string s;
	while ( cin >> s ) {
		if ( s.size() % 2 ) {
			printf( "NA\n" );
			continue;
		}
		string ans = "";
		for ( int i = 0; i < s.size(); i += 2 ) {
			if ( s[ i ] < '1' || '6' < s[ i ] || s[ i + 1 ] < '1' || '5' < s[ i + 1 ] ) {
				printf( "NA\n" );
				break;
			}
			ans += c[ s[ i ] - '1' ][ s[ i + 1 ] - '1' ];
		}
		if ( ans.size() != s.size() / 2 ) {
			continue;
		}
		printf( "%s\n", ans.c_str() );
		s.clear();
	}
	return 0;
}

C++: #include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(int a[][101],int b[],int c[],int d,int n,int p,int e,int w){
  int h,i;
  int z[101];
  int sm,mn=-1;
  if(p==e){
    do{
      h=0;
      for(i=1;i<d;i++){
	if(c[i-1]<c[i]){
	  swap(c[i-1],c[i]);
	  h=1;
	}
      }
    }while(h);
    sm=0;
    for(i=0;i<d;i++)
      sm+=i<w?c[i]/2:c[i];
    return sm;
  }
  if(b[p])
    return -1;
  memcpy(z,b,sizeof(z));
  z[p]=1;
  for(i=1;i<n+1;i++){
    if(a[p][i]!=-1){
      int tmp;
      c[d]=a[p][i];
      if((tmp=f(a,z,c,d+1,n,i,e,w))!=-1){
	if(mn==-1||mn>tmp)
	  mn=tmp;
      }
    }
  }
  return mn;
}
int main(){
  int i;
  int a[101][101],b[101],c[99],w,m,n,s,e;
  memset(b,0,sizeof(b));
  while(cin>>w>>n>>m>>s>>e&&w+n+m+s+e!=0){
    memset(a,-1,sizeof(a));
    for(i=0;i<m;i++){
      int p,q,r;
      cin>>p>>q>>r;
      a[p][q]=r;
      a[q][p]=r;
    }
    cout<<f(a,b,c,0,n,s,e,w)<<endl;
  }
  return 0;
}

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

using namespace std;

const int NODE = 100;
const int TICKET = 10 + 1;
const int INF = 1 << 20;	// 1048576

int E[NODE][NODE];
int cost[TICKET][NODE];
bool used[NODE];

void dijkstra ( int C, int N, int S )
{
	for (int c = 0; c <= C; ++c)
	{
		for (int i = 0; i < N; ++i)
			used[i] = false;
		
		cost[c][S] = 0;
		
		while ( 1 )
		{
			int v = -1;
			for (int i = 0; i < N; ++i)
				if ( !used[i] && ( v == -1 || cost[c][v] > cost[c][i] ))
					v = i;
			if ( v == -1 ) break;
			
			used[v] = true;
			
			if ( c )
				for (int i = 0; i < N; ++i)
				{
					cost[c][i] = min(cost[c][i], min(cost[c][v] + E[v][i] , cost[c-1][v] + E[v][i] / 2));
				}
			else
				for (int i = 0; i < N; ++i)
				{
					cost[c][i] = min(cost[c][i], cost[c][v] + E[v][i]);
				}
		}
	}
}

void init ( void )
{
	for (int i = 0; i < NODE; ++i)
	{
		for (int j = 0; j < NODE; ++j)
			E[i][j] = INF;
		for (int j = 0; j < TICKET; ++j)
			cost[j][i] = INF;
	}	
}

int main ( void )
{
	int c, n, m, s, d;
	
	while ( cin >> c >> n >> m >> s >> d,
		c | n | m | s | d )
	{
		init();
		
		for (int i = 0, a, b, f; i < m; i += 1)
		{
			cin >> a >> b >> f;
			E[a-1][b-1] = E[b-1][a-1] = f;
		}
		
		dijkstra( c, n, s-1 );
		
		cout << cost[c][d-1] << endl;
	}
	return 0;
}