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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define dump(o)                                                                \\
  { cerr << #o << " " << o << endl; }
#define dumpc(o)                                                               \\
  {                                                                            \\
    cerr << #o;                                                                \\
    for (auto e : (o))                                                         \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

//??¶?´?????????£???????????? int,double:INF ll:INFL
#define INFG INF
using Weight = double; // int;
class Edge {
public:
  int s;    // source
  int d;    // destination
  Weight w; // weight
  Edge(int s = 0, int d = 0, Weight w = INFG) : s(s), d(d), w(w){};
  bool operator<(const Edge &e) const { return w < e.w; }
};
using Edges = vector<Edge>;
//???????????\\: g[u].push_back(Edge(u, v, c));
//????????¨???????????????????????°??????????????\\?????????????????????
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

vector<int> ticket;
double cost[30][1 << 8];
int n, m, p, a, b;

void solve(const Graph &g, int s) {
  fill(cost[0], cost[30], INFG);
  typedef tuple<Weight, int, int>
      State; //?§?????????????????°?????????? ??? used
  queue<State> Q;
  cost[s][0] = 0;
  Q.push(State(0, s, 0)); //?§????
  while (!Q.empty()) {
    Weight d;
    int v;
    int used;
    tie(d, v, used) = Q.front();
    Q.pop();
    if (cost[v][used] > d)
      continue;
    for (auto &e : g[v]) { //??£??\\????????????????????¨????????????
      for (int i = 0; i < n; i++) {
        if ((used & (1 << i)) == (1 << i))
          continue;
        int dused = used | (1 << i);
        if (cost[e.d][dused] > cost[v][used] + e.w / ticket[i]) {
          cost[e.d][dused] = cost[v][used] + e.w / ticket[i];
          Q.push(State(cost[e.d][dused], e.d, dused));
        }
      }
    }
  }
}
int main() {
  /*

  n ??¬????????°
  m ????????°
  p ????????°
  a ????????° b ????????°

  t ??¬?????°
  x y ?????? z ?????¢

  */
  cout << fixed << setprecision(4);
  for (; scanf("%d%d%d%d%d", &n, &m, &p, &a, &b), n;) {
    ticket.resize(n);
    --a;
    --b;
    for (int i = 0; i < n; i++)
      scanf("%d", &ticket[i]);
    Graph g(m);
    for (int i = 0; i < p; i++) {
      int x, y, z;
      scanf("%d%d%d", &x, &y, &z);
      --x;
      --y;
      g[x].push_back(Edge(x, y, z));
      g[y].push_back(Edge(y, x, z));
    }
    if (p == 0) {
      cout << "Impossible" << endl;
      continue;
    }
    solve(g, a);
    double ans = INFG;
    // dumpc(cost[b]);
    for (auto &e : cost[b]) {
      ans = min(ans, e);
    }
    if (ans == INFG)
      cout << "Impossible" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define dump(o)                                                                \\
  { cerr << #o << " " << o << endl; }
#define dumpc(o)                                                               \\
  {                                                                            \\
    cerr << #o;                                                                \\
    for (auto e : (o))                                                         \\
      cerr << " " << e;                                                        \\
    cerr << endl;                                                              \\
  }
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

//??¶?´?????????£???????????? int,double:INF ll:INFL
#define INFG INF
using Weight = double; // int;
class Edge {
public:
  int s;    // source
  int d;    // destination
  Weight w; // weight
  Edge(int s = 0, int d = 0, Weight w = INFG) : s(s), d(d), w(w){};
  bool operator<(const Edge &e) const { return w < e.w; }
};
using Edges = vector<Edge>;
//???????????\\: g[u].push_back(Edge(u, v, c));
//????????¨???????????????????????°??????????????\\?????????????????????
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

vector<int> ticket;
double cost[30][1 << 8];
int n, m, p, a, b;

void solve(const Graph &g, int s) {
  fill(cost[0], cost[30], INFG);
  typedef tuple<Weight, int, int>
      State; //?§?????????????????°?????????? ??? used
  queue<State> Q;
  cost[s][0] = 0;
  Q.push(State(0, s, 0)); //?§????
  while (!Q.empty()) {
    Weight d;
    int v;
    int used;
    tie(d, v, used) = Q.front();
    Q.pop();
    if (cost[v][used] > d)
      continue;
    for (auto &e : g[v]) { //??£??\\????????????????????¨????????????
      for (int i = 0; i < n; i++) {
        if ((used & (1 << i)) == (1 << i))
          continue;
        int dused = used | (1 << i);
        if (cost[e.d][dused] > cost[v][used] + e.w / ticket[i]) {
          cost[e.d][dused] = cost[v][used] + e.w / ticket[i];
          Q.push(State(cost[e.d][dused], e.d, dused));
        }
      }
    }
  }
}
int main() {
  /*

  n ??¬????????°
  m ????????°
  p ????????°
  a ????????° b ????????°

  t ??¬?????°
  x y ?????? z ?????¢

  */
  cout << fixed << setprecision(4);
  for (; scanf("%d%d%d%d%d", &n, &m, &p, &a, &b), n;) {
    ticket.resize(n);
    --a;
    --b;
    for (int i = 0; i < n; i++)
      scanf("%d", &ticket[i]);
    Graph g(m);
    for (int i = 0; i < p; i++) {
      int x, y, z;
      scanf("%d%d%d", &x, &y, &z);
      --x;
      --y;
      g[x].push_back(Edge(x, y, z));
      g[y].push_back(Edge(y, x, z));
    }
    if (p == 0) {
      cout << "Impossible" << endl;
      continue;
    }
    solve(g, a);
    double ans = INFG;
    dumpc(cost[b]);
    for (auto &e : cost[b]) {
      ans = min(ans, e);
    }
    if (ans == INFG)
      cout << "Impossible" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}