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++: //Solution for aoj:0212 Highway Express Bus
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
typedef pair<int, int>P;
typedef pair < P, int > PP;
#define f first
#define s second

//struct S {
//	int cost, to, num;
//	S(int c, int t, int n) : cost(c), to(t), num(n){}
//	bool operator>(const S &s) const {
//		return cost > s.cost;
//	}
//};

const int INF = 1 << 29;
int c, n, m, s, d, ans;
int tocost[1000][11];
vector<P> town[1000];
priority_queue<PP, vector<PP>, greater<PP> > pq;


void dijkstra(){
	while (!pq.empty()){
		PP a = pq.top();
		pq.pop();
		for (int i = 0; i < town[a.f.s].size(); i++){
			int tt = town[a.f.s][i].f, cc = town[a.f.s][i].s;
			if (tocost[tt][a.s] > cc + a.f.f){
				tocost[tt][a.s] = cc + a.f.f;
				pq.push({ { cc + a.f.f, tt }, a.s });
			}
			if (a.s&&tocost[tt][a.s-1] > cc/2 + a.f.f){
				tocost[tt][a.s-1] = cc/2 + a.f.f;
				pq.push({ { cc / 2 + a.f.f, tt }, a.s - 1 });
			}
		}
	}
}
	int main(){
		while (cin >> c >> n >> m >> s >> d&&c&&n&&m&&s){
			for (int i = 0; i < 1000; i++)
				fill(tocost[i], tocost[i] + 11, INF);
			tocost[s][c] = 0;
			ans = INF;
			while (pq.size())
				pq.pop();
			for (int i = 0; i < 1000; i++)
				town[i].clear();
			for (int i = 0; i < m; i++){
				int a, b, c;
				cin >> a >> b >> c;
				town[a].push_back({ b, c });
				town[b].push_back({ a, c });
			}
			pq.push({ { 0, s }, c });
			dijkstra();
			for (int i = 0; i <= c; i++)
				ans = min(ans, tocost[d][i]);
			cout << ans << endl;
		}
		return 0;
	}

C++: #include<iostream>
#include<algorithm>
using namespace std;
const int INF = (1<<21);
int c,n,m,s,d;
int G[100][100];


int dij(){
  int D[100][11];
  bool V[100][11];
  for(int i=0;i<n;i++){
    for(int j=0;j<c+1;j++){
      D[i][j]=INF;
      V[i][j]=false;
    }
  }
    
  D[s][c]=0;
  while(1){
    int minv=INF,u,v;
    for(int i=0;i<n;i++){
      for(int j=0;j<c+1;j++){
	if(!V[i][j] && D[i][j]<minv){
	  minv=D[i][j];
	  u=i;
	  v=j;
	}
      }
    }

    if(minv==INF){
      break;
    }

    V[u][v]=true;
    for(int i=0;i<n;i++){
      if(G[u][i]==INF) continue;
      D[i][v]=min(D[i][v],D[u][v]+G[u][i]);
      if( v ){
	D[i][v-1]=min(D[i][v-1],D[u][v]+(G[u][i]/2));
      } 
    }
  }
    
    int minv=INF;
    for(int i=0;i<c+1;i++){
      minv=min(minv,D[d][i]);
    }
    return minv;
}



int main(){
  
  while(cin>> c>> n>> m>> s>> d,c){
    s--;
    d--;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	G[i][j]=INF;
      }
    }

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

    cout<< dij()<< endl;
  }
}

Python: from sys import stdin
readline = stdin.readline



from collections import namedtuple
Runner = namedtuple('Runner', 'd v')

def main():
    while True:
        ticket, vertex, edge, start, destination = map(int, readline().split())
        if ticket == 0:
            break

        start -= 1
        destination -= 1
        g = defaultdict(list)
        for i in range(edge):
            s, t, length = map(int, readline().split())
            s -= 1
            t -= 1
            g[s].append((length, t))
            g[t].append((length, s))
        
        d = ex_dijkstra(g, vertex, start, ticket)
        print(min(d[destination]))



from heapq import heappush, heappop
from collections import defaultdict
def ex_dijkstra(g, size, start, ticket):
    d = [[float('inf')] * (ticket + 1) for i in range(size)]
    d[start][ticket] = 0
    heap = [(d[start][ticket], start, ticket)]
    while heap:
        du, u, ticket = heappop(heap)
        for length, v in g[u]:
            if d[v][ticket] > du + length:
                d[v][ticket] = du + length
                heappush(heap,(d[v][ticket], v, ticket))
            if ticket and d[v][ticket - 1] > du + length // 2:
                d[v][ticket - 1] = du + length // 2
                heappush(heap,(d[v][ticket - 1], v, ticket - 1))

    return d

main()

Python: from sys import stdin
from heapq import heappush,heappop

while(True):
    c,n,m,s,d = map(int, stdin.readline().split())
    if not c: break
    ma = [[] for _ in range(n)]
    s -= 1
    d -= 1
    for _ in range(m):
        a,b,f = map(int, stdin.readline().split())
        a -= 1
        b -= 1
        ma[a].append([f,b])
        ma[b].append([f,a])
    cost = [[10**10]*(c+1) for _ in range(n)]
    cost[s][c] = 0
    que = [[ cost[s][c], s, c ]]
    while que:
        co, pl, ti = heappop(que)
        for fee, town in ma[pl]:
            if cost[town][ti] > co+fee:
                cost[town][ti] = co+fee
                heappush(que,[cost[town][ti],town,ti])
            if ti and cost[town][ti-1] > co+fee//2:
                cost[town][ti-1] = co+fee//2
                heappush(que,[cost[town][ti-1],town,ti-1])
    print(min(cost[d]))

Python: from heapq import *
def dijkstra(s,c):
    que=[]
    dp[0][s]=0
    heappush(que,[dp[c][s],s])

    while len(que)!=0:
        p=heappop(que)
        v=p[1] #v is the current location
        if(dp[c][v]<p[0]):
            continue
        for i in range(len(G[v])):
            e=G[v][i]
            Min=dp[c][v]+e[1] if c==0 else min(dp[c-1][v]+e[1]/2,dp[c][v]+e[1])
            if(dp[c][e[0]]>Min):
                dp[c][e[0]]=Min
                heappush(que,[dp[c][e[0]],e[0]])

while True:
    #input c,n,m,s,d & creating G
    #G[to,cost]
    c,n,m,s,d=map(int,input().split())
    
    if c==n==m==s==d==0:
        break
    
    G=[[]]
    for i in range(n):
        G.append([])
    for i in range(m):
        a,b,f=map(int,input().split())
        G[a].append([b,f])
        G[b].append([a,f])

    #creating dp[]
    INF=1e8
    dp=[]
    for i in range(c+1):
        temp=[INF for j in range(n+1)]
        dp.append(temp)

    for i in range(c+1):
        dijkstra(s,i)
    print(int(dp[c][d]))