Problem p00719 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <set>
#include <vector>
#ifndef LIB_REPEAT_HPP
#define LIB_REPEAT_HPP
#define repeat(i, n) for (int i = 0; i < (n); ++i)
#define repeat_from(i, m, n) for (int i = (m); i < (n); ++i)
#define repeat_one(i, n) for (int i = 1; i <= (n); ++i)
#define repeat_rev(i, n) for (int i = (n)-1; 0 <= i; --i)
#define foreach(it, cont)                                                      \\
  for (decltype(cont.begin()) it = cont.begin(); it != cont.end(); ++it)
#endif
#ifndef LIB_TYPEDEF_LL_HPP
#define LIB_TYPEDEF_LL_HPP
typedef long long ll;
typedef unsigned long long ull;
#endif
using namespace std;
typedef unsigned int uint;
struct edge_t {
  int to, cost;
};
struct state_t {
  int pos;
  uint used;
  double time;
};
bool operator>=(const state_t &a, const state_t &b) { return a.time >= b.time; }
int main() {
  ios_base::sync_with_stdio(false);
  while (true) {
    int N, M, P, A, B;
    cin >> N >> M >> P >> A >> B;
    if (N == 0 and M == 0 and P == 0 and A == 0 and B == 0)
      break;
    --A;
    --B;
    vector<int> ticket(N);
    repeat(i, N) cin >> ticket[i];
    vector<vector<edge_t>> town(M);
    repeat(i, P) {
      int x, y, z;
      cin >> x >> y >> z;
      --x;
      --y;
      town[x].push_back((edge_t){y, z});
      town[y].push_back((edge_t){x, z});
    }
    priority_queue<state_t, vector<state_t>, greater_equal<state_t>> que;
    que.push((state_t){A, 0, 0});
    set<pair<int, uint>> visited;
    while (not que.empty()) {
      const state_t s = que.top();
      que.pop();
      if (visited.count(make_pair(s.pos, s.used)))
        continue;
      visited.insert(make_pair(s.pos, s.used));
      if (s.pos == B) {
        cout << s.time << endl;
        goto next;
      }
      for (auto e : town[s.pos]) {
        repeat(n, N) if (not(s.used & (1 << n))) {
          state_t t = s;
          t.used |= (1 << n);
          t.pos = e.to;
          t.time += e.cost / (double)ticket[n];
          que.push(t);
        }
      }
    }
    cout << "Impossible" << endl;
  next:;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <queue>
#include <set>
#include <vector>
#ifndef LIB_REPEAT_HPP
#define LIB_REPEAT_HPP
#define repeat(i, n) for (int i = 0; i < (n); ++i)
#define repeat_from(i, m, n) for (int i = (m); i < (n); ++i)
#define repeat_one(i, n) for (int i = 1; i <= (n); ++i)
#define repeat_rev(i, n) for (int i = (n)-1; 0 <= i; --i)
#define foreach(it, cont)                                                      \\
  for (decltype(cont.begin()) it = cont.begin(); it != cont.end(); ++it)
#endif
#ifndef LIB_TYPEDEF_LL_HPP
#define LIB_TYPEDEF_LL_HPP
typedef long long ll;
typedef unsigned long long ull;
#endif
using namespace std;
typedef unsigned int uint;
struct edge_t {
  int to, cost;
};
struct state_t {
  int pos;
  uint used;
  double time;
};
bool operator>=(const state_t &a, const state_t &b) { return a.time >= b.time; }
int main() {
  ios_base::sync_with_stdio(false);
  while (true) {
    int N, M, P, A, B;
    cin >> N >> M >> P >> A >> B;
    if (N == 0 and M == 0 and P == 0 and A == 0 and B == 0)
      break;
    --A;
    --B;
    vector<int> ticket(N);
    repeat(i, N) cin >> ticket[i];
    vector<vector<edge_t>> town(M);
    repeat(i, P) {
      int x, y, z;
      cin >> x >> y >> z;
      --x;
      --y;
      town[x].push_back((edge_t){y, z});
      town[y].push_back((edge_t){x, z});
    }
    priority_queue<state_t, vector<state_t>, greater_equal<state_t>> que;
    que.push((state_t){A, 0, 0});
    while (not que.empty()) {
      const state_t s = que.top();
      que.pop();
      if (s.pos == B) {
        cout << s.time << endl;
        goto next;
      }
      for (auto e : town[s.pos]) {
        repeat(n, N) if (not(s.used & (1 << n))) {
          state_t t = s;
          t.used |= (1 << n);
          t.pos = e.to;
          t.time += e.cost / (double)ticket[n];
          que.push(t);
        }
      }
    }
    cout << "Impossible" << endl;
  next:;
  }
  return 0;
}