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, 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]int)
		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}] = now.Amount
			for _, v := range pointMap[now.NowPosition] {
				next := &Node{v.NextPoint, now.DiscountTicketTCount, now.Amount + v.Fee}
				if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
					memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
					heap.Push(&pq, next)
				}
				if now.DiscountTicketTCount > 0 {
					next = &Node{v.NextPoint, now.DiscountTicketTCount - 1, now.Amount + v.Fee/2}
					if memoAmount, ok := memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}]; !ok || (ok && memoAmount > next.Amount) {
						memo[Memo{NowPoint: v.NextPoint, DiscountTicketTCount: now.DiscountTicketTCount}] = next.Amount
						heap.Push(&pq, next)
					}
				}
			}
		}
		//runtime.GC()
	}
}

C++: #include<stdio.h>
#include<string.h>
#include<utility>
#include<queue>
#include<algorithm>
using namespace std;
#define INF 1000000000
int C,N,M,S,D,g1[101][101],g2[101][101],s,t,c,d[10][101];
typedef struct P{int p,c,t;}P;
struct Order
{
	bool operator ()(P const& a, P const& b) const
	{
		return a.c==b.c?a.t<b.t:a.c>b.c;
	}
};

P tmp,tmp2;
priority_queue<P,vector<P>,Order>Q;
int main()
{
	for(;scanf("%d%d%d%d%d",&C,&N,&M,&S,&D),C;)
	{
		for(int i=0;i<=N;i++)
			for(int j=0;j<=N;j++)
				g1[i][j]=g2[i][j]=INF;
		for(int i=0;i<=C;i++)
			for(int j=0;j<=N;j++)
				d[i][j]=INF;
		for(int i=0;i<M;i++)
		{
			scanf("%d%d%d",&s,&t,&c);
			if(g1[s][t]>c)
			{
				g1[s][t]=g1[t][s]=c;
				g2[s][t]=g2[t][s]=c/2;
			}
		}
		d[C][S]=0;
		tmp.c=0;tmp.p=S;tmp.t=C;
		Q.push(tmp);
		for(;!Q.empty();)
		{
			tmp=Q.top(),Q.pop();
			for(int i=1;i<=N;i++)
			{
				int nc=tmp.c+g1[tmp.p][i];
				if(d[tmp.t][i]>nc)
				{
					tmp2.c=d[tmp.t][i]=nc;
					tmp2.p=i;
					tmp2.t=tmp.t;
					Q.push(tmp2);
				}
				nc=tmp.c+g2[tmp.p][i];
				if(tmp.t>0&&d[tmp.t-1][i]>nc)
				{
					tmp2.c=d[tmp.t-1][i]=nc;
					tmp2.p=i;
					tmp2.t=tmp.t-1;
					Q.push(tmp2);
				}
			}
		}
		printf("%d\n",d[0][D]);
	}
}

C++: #include<stdio.h>
#include<string.h>
#include<utility>
#include<queue>
#include<algorithm>
using namespace std;
#define INF 1000000000
int C,N,M,S,D,g1[101][101],s,t,c,d[11][101];
typedef struct P{int p,c,t;}P;
struct Order
{
	bool operator ()(P const& a, P const& b) const
	{
		return a.c>b.c;
	}
};

P tmp,tmp2;
priority_queue<P,vector<P>,Order>Q;
int main()
{
	for(;scanf("%d%d%d%d%d",&C,&N,&M,&S,&D),N;)
	{
		for(int i=0;i<=N;i++)
			for(int j=0;j<=N;j++)
				g1[i][j]=INF;
		for(int i=0;i<=C;i++)
			for(int j=0;j<=N;j++)
				d[i][j]=INF;
		for(int i=0;i<M;i++)
		{
			scanf("%d%d%d",&s,&t,&c);
			if(g1[s][t]>c)
				g1[s][t]=g1[t][s]=c;
		}
		d[C][S]=0;
		tmp.c=0;tmp.p=S;tmp.t=C;
		Q.push(tmp);
		for(;!Q.empty();)
		{
			tmp=Q.top(),Q.pop();
			for(int i=0;i<=N;i++)
			{
				int nc=tmp.c+g1[tmp.p][i];
				if(d[tmp.t][i]>nc)
				{
					tmp2.c=d[tmp.t][i]=nc;
					tmp2.p=i;
					tmp2.t=tmp.t;
					Q.push(tmp2);
				}
				nc=tmp.c+g1[tmp.p][i]/2;
				if(tmp.t>0&&d[tmp.t-1][i]>nc)
				{
					tmp2.c=d[tmp.t-1][i]=min(d[tmp.t][i],nc);
					tmp2.p=i;
					tmp2.t=tmp.t-1;
					Q.push(tmp2);
				}
			}
		}
		printf("%d\n",d[0][D]);
	}
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef long long ll;

const int MAX_SIZE = 10000;

struct edge{
	int to;
	int cost;
	int kipKind;
};

// ツノツーツドツづ個暗環置
vector<edge> G[101][11];
int d[101][11];
const int INF = 1000000000;


class Situation{
public:
	Situation(double _cost,int _node,int _used){
		cost = _cost;
		node = _node;
		used = _used;
	}

	Situation();

	double cost;
	int node;
	int used;

	bool operator<(const Situation &sit)const{
		return sit.cost < (this->cost);
	}
};

void dijkstra(int s,int g,int c){
	priority_queue<Situation> que;

	for(int i = 0; i < 101; i++)
		fill(d[i],d[i]+11,INF);
	d[s][c] = 0;

	que.push(Situation(0,s,c));
	while(!que.empty()){
		Situation p = que.top();
		que.pop();
		int v = p.node;
		int used = p.used;
		if(d[v][used] < p.cost)
			continue;
		for(int i = 0; i < G[v][used].size(); i++){
			edge e = G[v][used][i];
			if(d[e.to][e.kipKind] > d[v][used]+e.cost){
				d[e.to][e.kipKind] = d[v][used]+e.cost;
				que.push(Situation(d[e.to][e.kipKind],e.to,e.kipKind));
			}
		}

	}
	

	int minCost = INF;

	for(int i = 0; i <= c; i++){
		minCost = min(minCost,d[g][i]);
	}
	if(minCost != INF)
		cout << minCost << endl;
	else
		cout << "Impossible" << endl;
}



int main(){

	int n,m,s,d,c;
	while(cin>>c>>n>>m>>s>>d&&!(c==0&&n==0&&m==0&&s==0&&d==0)){
		s--;
		d--;
		for(int i = 0; i < m; i++){
			int from,to,cost;
			cin>>from>>to>>cost;
			from--;
			to--;
			for(int j = 0; j <= c; j++){
				if(j-1>=0){
					edge e;
					e.cost=cost/2;
					e.to=to;
					e.kipKind=j-1;
					G[from][j].push_back(e);
					e.to=from;
					G[to][j].push_back(e);
				}
				edge e;
				e.cost=cost;
				e.to=to;
				e.kipKind=j;
				G[from][j].push_back(e);
				e.to=from;
				G[to][j].push_back(e);
			}
		}
		dijkstra(s,d,c);
		for(int i = 0; i < 101; i++)
			for(int j = 0; j < 11; j++)
				G[i][j].clear();
		//cout<<endl;
	}


	return 0;
}