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

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x " = " << x << endl
#define print(x) cout << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<double, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX / 3
#define MAX_N 1000000001

struct Data {
  double c;
  int city, ticket;
};

bool operator<(const Data &a, const Data &b) { return a.c > b.c; }

int main() {
  cin.sync_with_stdio(false);
  int n, m, p, a, b, x, y, z;
  double ans;
  int t[8];
  double d[31][31];
  double cost[31][1 << 8];

  while (cin >> n >> m >> p >> a >> b, n) {
    rep(i, 31) rep(j, 31) d[i][j] = INF;
    rep(i, 31) rep(j, 1 << 8) cost[i][j] = INF;
    rep(i, n) cin >> t[i];
    rep(i, p) {
      cin >> x >> y >> z;
      d[x][y] = d[y][x] = z;
    }

    priority_queue<Data> q;
    q.push(Data{0, a, 0});
    ans = -1;
    while (!q.empty()) {
      Data data = q.top();
      q.pop();
      if (cost[data.city][data.ticket] != INF)
        continue;

      cost[data.city][data.ticket] = data.c;
      if (data.city == b) {
        ans = data.c;
        break;
      }

      repl(i, 1, m + 1) {
        if (d[data.city][i] == INF)
          continue;
        rep(j, n) {
          if ((data.ticket & (1 << j)) == 0) {
            q.push(Data{d[data.city][i] / t[j] + data.c, i,
                        data.ticket + (1 << j)});
          }
        }
      }
    }

    if (ans != -1) {
      printf("%.4f\\n", ans);
    } else {
      printf("Impossible\\n");
    }
  }

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x " = " << x << endl
#define print(x) cout << x << endl
#define maxch(x, y) x = max(x, y)
#define minch(x, y) x = min(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, int> PD;
typedef pair<PD, P> PDP;
typedef pair<double, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX / 3
#define MAX_N 1000000001

int t[8];
int d[31][31];

int main() {
  cin.sync_with_stdio(false);
  int n, m, p, a, b;

  while (cin >> n >> m >> p >> a >> b, n) {
    repl(i, 1, m + 1) repl(j, 1, m + 1) d[i][j] = INF;
    rep(i, n) cin >> t[i];
    rep(i, p) {
      int x, y, z;
      cin >> x >> y >> z;
      d[x][y] = d[y][x] = z;
    }
    // PDP(P(cost, city), P(ticket, visited))
    double ans = -1;
    priority_queue<PDP, vector<PDP>, greater<PDP>> q;
    q.push(PDP(PD(0, a), P(0, 0)));
    while (!q.empty()) {
      PDP p = q.top();
      q.pop();
      if (p.fi.se == b) {
        ans = p.fi.fi;
        break;
      }
      p.se.se += (1 << (a - 1));
      repl(i, 1, m + 1) {
        if (d[p.fi.se][i] != INF && (p.se.se & (1 << (m - 1))) == 0) {
          rep(j, n) {
            if ((p.se.fi & 1 << j) == 0) {
              q.push(PDP(PD(p.fi.fi + (double)d[p.fi.se][i] / t[j], i),
                         P(p.se.fi + (1 << j), p.se.se)));
            }
          }
        }
      }
    }

    if (ans == -1) {
      print("Impossible");
    } else {
      printf("%.4f\\n", ans);
    }
  }

  return 0;
}