Language: C++

#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const LL MOD = 1000000007;// 10^9+7
const int INF = (1 << 30);


struct Stage {
	Stage(int n_, int m_, int p_, int a_, int b_):
		n(n_),
		m(m_),
		p(p_),
		a(a_),
		b(b_)
	{
		t.resize(n);
		edge.resize(m);

		REP(i, n) {
			int tmp;
			cin >> tmp;
			t[i] = tmp;
		}
		REP(i, p) {
			int x, y, z;
			cin >> x >> y >> z;
			x--; y--;
			edge[x].push_back({ y,z });
			edge[y].push_back({ x,z });
		}
	}

	void action()
	{
		double res = INF;
		sort(t.begin(), t.end());
		do {
			/*
			{
				double tmp = search_route(t);
				if (res > tmp) {
					cerr << "updated:" << endl;
					debug(t);
					cerr << "ans:" << tmp << endl << endl;
				}
			}
			*/
			res = min(res, search_route(t));
		} while (next_permutation(t.begin(), t.end()));
		//cerr << "answer is::::  ";
		cout << (is_reach(res)
			? to_string(res)
			: "Impossible" )
		<< endl;
	}

private:
	const int n, m, p, a, b;
	vector<int> t;
	vector<vector<pair<int, int>>> edge;

	bool is_reach(double res)	{
		return res < INF / 2.;
	}

	double search_route(vector<int> t)
	{
		queue<int> now, will;
		unique_ptr<double[]> time(new double[m]), willTime(new double[m]);
		REP(i, m) {
			time[i] = willTime[i] = INF;
		}
		time[a] = 0;
		willTime[a] = 0;
		now.push(a);
		
		//チケットを順番に使う。
		for (int ticket : t) 
		{
			//消費対象は、辿り着いた土地に対して
			while (!now.empty())
			{
				int here = now.front(); now.pop();
				//消費する
				for (auto route : edge[here])
				{
					int next = route.first;
					int dist = route.second;
					double additional = 1.*dist / ticket;
					if (willTime[next] >= time[here] + additional)
					{
						willTime[next] = time[here] + additional;
						will.push(next);
					}
				}
			}
			now.swap(will);
			REP(i, m) {
				time[i] = willTime[i];
			}
		}

		return time[b];
	}

	void debug(vector<int> v)
	{
		for (auto num : v)cerr << num << " ";
		cerr << endl;
	}
};


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	while (true)
	{
		int n, m, p, a, b;
		cin >> n >> m >> p >> a >> b;
		if (n == 0)break;
		a--; b--;

		Stage stage(n, m, p, a, b);
		stage.action();
	}
	//debug();
	
	return 0;
}



Compiler output:
a.cc: In member function 'double Stage::search_route(std::vector<int>)':
a.cc:88:17: error: 'unique_ptr' was not declared in this scope
   88 |                 unique_ptr<double[]> time(new double[m]), willTime(new double[m]);
      |                 ^~~~~~~~~~
a.cc:13:1: note: 'std::unique_ptr' is defined in header '<memory>'; this is probably fixable by adding '#include <memory>'
   12 | #include<fstream>
  +++ |+#include <memory>
   13 | 
a.cc:88:28: error: expected primary-expression before 'double'
   88 |                 unique_ptr<double[]> time(new double[m]), willTime(new double[m]);
      |                            ^~~~~~
a.cc:90:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   90 |                         time[i] = willTime[i] = INF;
      |                               ^
a.cc:90:35: error: 'willTime' was not declared in this scope
   90 |                         time[i] = willTime[i] = INF;
      |                                   ^~~~~~~~
a.cc:92:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   92 |                 time[a] = 0;
      |                       ^
a.cc:92:25: error: assignment of read-only location '*(time + ((sizetype)((Stage*)this)->Stage::a))'
   92 |                 time[a] = 0;
      |                 ~~~~~~~~^~~
a.cc:93:17: error: 'willTime' was not declared in this scope
   93 |                 willTime[a] = 0;
      |                 ^~~~~~~~
a.cc:109:72: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  109 |                                         if (willTime[next] >= time[here] + additional)
      |                                                                        ^
a.cc:109:74: error: invalid operands of types 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'} and 'double' to binary 'operator+'
  109 |                                         if (willTime[next] >= time[here] + additional)
      |                                                               ~~~~~~~~~~ ^ ~~~~~~~~~~
      |                                                                        |   |
      |                                                                        |   double
      |                                                                        time_t(time_t*) noexcept {aka long int(long int*) noexcept}
a.cc:111:75: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  111 |                                                 willTime[next] = time[here] + additional;
      |                                                                           ^
a.cc:111:77: error: invalid operands of types 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'} and 'double' to binary 'operator+'
  111 |                                                 willTime[next] = time[here] + additional;
      |                                                                  ~~~~~~~~~~ ^ ~~~~~~~~~~
      |                                                                           |   |
      |                                                                           |   double
      |                                                                           time_t(time_t*) noexcept {aka long int(long int*) noexcept}
a.cc:118:39: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  118 |                                 time[i] = willTime[i];
      |                                       ^
a.cc:122:30: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  122 |                 return time[b];
      |                              ^
a.cc:122:30: error: cannot convert 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'double' in return
  122 |                 return time[b];
      |                              ^
      |                              |
      |                              time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}