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>
#include <queue>
using namespace std;

struct State {
    int no_;
    int cost_;
    int ticket_;
    State(int no, int cost, int ticket) 
        : no_(no), cost_(cost), ticket_(ticket) {} 
    
};

struct Edge {
    int to_;
    int cost_;
    Edge(int to, int cost) 
        : to_(to), cost_(cost) {}
};

int c, n, m, s, d;

auto dijkstra(vector<vector<Edge>> &g, vector<vector<int>> &dm) -> int {
    auto comp = [](auto& lhs, auto& rhs){return lhs.cost_ > rhs.cost_;};
    priority_queue<State, vector<State>, decltype(comp)> que(comp);

    que.push(State(s, 0, c));
    for (auto &e : dm[s]) {
        e = 0;
    }
    while (!que.empty()) {
        State s = que.top();
        que.pop();
        int current_no = s.no_;
        int current_cost = s.cost_;
        int current_ticket = s.ticket_;
        for (auto &e : g[current_no]) {
            int to = e.to_;
            int cost = e.cost_;
            if (current_ticket > 0) {
                // not use ticket
                if (dm[to][current_ticket] > dm[current_no][current_ticket] + cost) {
                    que.push(State(to, dm[current_no][current_ticket] + cost, current_ticket));
                    dm[to][current_ticket] = dm[current_no][current_ticket] + cost;
                }
                // use ticket
                if (dm[to][current_ticket-1] > dm[current_no][current_ticket] + cost/2) {
                    que.push(State(to, dm[current_no][current_ticket] + cost/2, current_ticket-1));
                    dm[to][current_ticket-1] = dm[current_no][current_ticket-1] + cost/2;
                }
            }else {
                if (dm[to][current_ticket] > dm[current_no][current_ticket] + cost) {
                    que.push(State(to, dm[current_no][current_ticket] + cost, current_ticket));
                    dm[to][current_ticket] = dm[current_no][current_ticket] + cost;
                }
            }
        }
    }

    int ans = 1e8;
    for (auto &e : dm[d]) {
        ans = min(ans, e);
    }
    return ans;
}

auto main(int argc, char const *argv[]) -> int {
    constexpr int INF = 1e8;

    while(cin>>c>>n>>m>>s>>d, c||n||m||s||d) {
        vector<vector<Edge>> g(n+1);
        vector<vector<int>> dm(n+1);
        for (auto &e : dm) {
            for (int i = 0; i < c + 1; ++i) {
                e.push_back(INF);
            }
        }

        for (int i = 0; i < m; ++i) {
            int a, b, f;
            cin>>a>>b>>f;
            g[a].push_back(Edge(b, f));
            g[b].push_back(Edge(a, f));
        }
        cout<<dijkstra(g, dm)<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

struct Data{
    int cost,p,tk;
    Data(){}
    Data(int _cost,int _p,int _tk){
        cost=_cost; p=_p; tk=_tk;
    }
    bool operator<(const Data &a)const{
        return cost>a.cost;
    }
};

struct Way{
    int to,cost;
    Way(){}
    Way(int _to,int _cost){
        to=_to; cost=_cost;
    }
};

int main(){
    int C,N,M,S,D,A,B,F;
    while(cin>>C>>N>>M>>S>>D,C||N||M||S||D){
        vector<Way> way[501];
        for(int i=0;i<M;i++){
            cin>>A>>B>>F;
            way[A].push_back(Way(B,F));
            way[B].push_back(Way(A,F));
        }

        priority_queue<Data> q;
        q.push(Data(0,S,0));
        Data q_c;
        bool memo[101][11]={};
        while(!q.empty()){
            q_c = q.top(); q.pop();
            if(q_c.p==D){
                printf("%d\n",q_c.cost);
                break;
            }
            if(memo[q_c.p][q_c.tk]) continue;
            memo[q_c.p][q_c.tk]=true;
            for(int i=0;i<way[q_c.p].size();i++){
                if(q_c.tk<C)
                    q.push(Data(q_c.cost+(way[q_c.p][i].cost)/2,way[q_c.p][i].to,q_c.tk+1));
                q.push(Data(q_c.cost+way[q_c.p][i].cost,way[q_c.p][i].to,q_c.tk));
            }
        }
    }
    return 0;
}

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;

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