Language: C++

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

#define INF 10000
#define MAXN 30
#define MAXM 8

int T[MAXN];
int G[MAXM][MAXM];
double dp[MAXM][1 << MAXN];
bool used[MAXM][1 << MAXN];
int n, m, p, a, b;

double dijkstra(){
    for (int i = 0; i < MAXM; i++) {
        for (int j = 0; j < (1 << MAXN); j++) {
            dp[i][j] = INF;
            used[i][j] = false;
        }
    }
    dp[a][(1 << n) - 1] = 0;
    
    while (true) {
        int v = -1;
        int w;
        for (int u = 0; u < m; u++) {
            for (int s = 0; s < (1 << n); s++) {
                if (!used[u][s] && (v == -1 || dp[u][s] < dp[v][s])) {
                    v = u; w = s;
                }
            }
        }
        if (v == -1) {
            break;
        }
        used[v][w] = true;
        for (int u = 0; u < m; u++) {
            for (int i = 0; i < n; i++) {
                if (G[v][u] == INF) {
                    continue;
                }
                if (w >> i & 1) {
                    dp[u][w & ~(1 << i)] = min(dp[u][w & ~(1 << i)], dp[v][w] + (double)G[v][u] / T[i]);
                }
            }
        }
    }
//    for (int i = 0; i < m; i++) {
//        for (int j = 0; j < (1<<n); j++) {
//            cout << dp[i][j] <<" ";
//        }
//        cout << endl;
//    }
    double ans = INF;
    for (int i = 0; i < (1 << n); i++) {
        ans = min(ans, dp[b][i]);
    }
    return ans;
}

int main()
{
    int x, y ,z;
    while (true) {
        cin >> n >> m >> p >> a >> b;
        if (n == 0 && m == 0) {
            break;
        }
        a--; b--;
        for (int i = 0; i < MAXM; i++) {
            for (int j = 0; j < MAXM; j++) {
                G[i][j] = INF;
            }
        }
        for (int i = 0; i < MAXM; i++) {
            G[i][i] = 0;
        }
        for (int i = 0; i < n; i++) {
            cin >> T[i];
        }
        for (int i = 0; i < p; i++) {
            cin >> x >> y >> z;
            x--; y--;
            G[x][y] = G[y][x] = z;
        }
        double res = dijkstra();
        if (res == INF) {
            cout << "Impossible" << endl;
        }else{
            printf("%.3f\n", res);
        }
    }
    

    return 0;
}

Compiler output:
/tmp/ccJfHiNs.o: in function `dijkstra()':
a.cc:(.text+0x5d): relocation truncated to fit: R_X86_64_PC32 against symbol `used' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x80): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x86): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0xf0): relocation truncated to fit: R_X86_64_PC32 against symbol `used' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x16b): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x189): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x1b5): relocation truncated to fit: R_X86_64_PC32 against symbol `used' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x322): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x335): relocation truncated to fit: R_X86_64_PC32 against symbol `m' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x360): relocation truncated to fit: R_X86_64_PC32 against symbol `b' defined in .bss section in /tmp/ccJfHiNs.o
a.cc:(.text+0x3a3): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status