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
}

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)
		}
		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)
		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)
					}
				}
			}
		}
	}
}

Python: 
while True:
    c,n,m,s,d = list(map(int,input().split()))

    if c==0 and n == 0 and m == 0 and s == 0 and d == 0 : break

    f_list = [[ 0 for i in range(n+1)] for j in range(n+1)]
    path = {}
    for i in range(m):
        a,b,f = (list(map(int,input().split())))

        def add_path(a,b,f):
            global path
            global f_list
            if not a in path:
                path[a] = [b]
            else:
                path[a].append(b)
            f_list[a][b] = f

        add_path(a,b,f)
        add_path(b,a,f)

    #keiro tansaku
    stack = []
    stack.append(path[s])
    min_path  = None
    min_val = 999999999999

    work_val = []
    work_path = []
    def path_val(path):
        global c
        path.sort()
        v = 0
        if len(path) < c:
            v = sum(path) / 2
        else:
            v = sum(path[-c:])/2
            v += sum(path[:-c])

        return v
        
    work_path.append(s)
    work_val.append(0)

    while len(stack) > 0:


        ham = stack[-1]
        if len(ham) == 0:
            # 1階層上に
            stack.pop()
            work_val.pop()
            work_path.pop()
            continue

        next_p = ham.pop()

        if next_p in work_path: #already passed
            continue

        work_val.append(f_list[work_path[-1]][next_p])
        work_path.append(next_p)

        if next_p == d: #goal
            spam_val = path_val(work_val)
            if min(spam_val,min_val) != min_val:
                min_val = spam_val
            work_val.pop()
            work_path.pop()

        else:
            stack.append(path[next_p])

    print(int(min_val))

Python: 
while True:
    c,n,m,s,d = list(map(int,input().split()))

    if c==0 and n == 0 and m == 0 and s == 0 and d == 0 : break

    f_list = [[ 0 for i in range(n+1)] for j in range(n+1)]
    path = {}
    for i in range(m):
        a,b,f = (list(map(int,input().split())))

        def add_path(a,b,f):
            global path
            global f_list
            if not a in path:
                path[a] = [b]
            else:
                path[a].append(b)
            f_list[a][b] = f

        add_path(a,b,f)
        add_path(b,a,f)

    #keiro tansaku
    stack = []
    stack.append(path[s])
    min_path  = None
    min_val = 999999999999

    work_val = []
    work_path = []
    def path_val(path):
        global c
        path.sort()
        v = 0
        if len(path) < c:
            v = sum(path) / 2
        else:
            v = sum(path[-c:])/2
            v += sum(path[:-c])

        return v
        
    work_path.append(s)
    work_val.append(0)

    while len(stack) > 0:


        ham = stack[-1]
        if len(ham) == 0:
            # 1階層上に
            stack.pop()
            work_val.pop()
            work_path.pop()
            continue

        next_p = ham.pop()

        if next_p in work_path: #already passed
            continue

        work_val.append(f_list[work_path[-1]][next_p])
        work_path.append(next_p)

        if next_p == d: #goal
            spam_val = path_val(work_val[:])
            if min(spam_val,min_val) != min_val:
                min_val = spam_val
            work_val.pop()
            work_path.pop()

        else:
            stack.append(path[next_p][:])

    print(int(min_val))

Python: import heapq

Python: from heapq import *

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)

    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]])

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

Python: from heapq import *

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)

    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]])

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