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

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <utility>
#include <vector>

const int INF = (1 << 28);

using namespace std;

typedef pair<unsigned char, int> pci;
typedef pair<double, pci> C; // ??????????????£?????¬?????????????????´???

double d[256][31]; // ?????£?????¬????????¶?????????????????´???

int main(void) {
  int n, m, p, a, b;

  while (cin >> n >> m >> p >> a >> b, n + m + p + a + b) {
    for (int i = 0; i < 256; i++) {
      for (int j = 0; j < 31; j++) {
        d[i][j] = INF;
      }
    }

    vector<int> t(n); // ??¬???
    for (int i = 0; i < n; i++) {
      cin >> t[i];
    }
    vector<vector<int>> city(
        m + 1,
        vector<int>(m +
                    1)); // ????????¨?????????????????????????????£????????????
    for (int i = 0; i <= m; i++) {
      for (int j = 0; j <= m; j++) {
        city[i][j] = INF;
      }
    }
    int x, y, z;
    for (int i = 0; i < p; i++) {
      cin >> x >> y >> z;
      city[x][y] = z;
      city[y][x] = z;
    }

    priority_queue<C, vector<C>, greater<C>> que;
    que.push(C(0, pci(0, a)));
    d[0][a] = 0;
    while (!que.empty()) {
      C c = que.top();
      que.pop();
      int cn = c.second.second;              // ???????????????
      unsigned char ticket = c.second.first; // ?????£???????????¬???
      // ?????£????????????????????°?????°??????
      int cnt = 0;
      for (int i = 0; i < 8; i++) {
        cnt += (ticket >> i) & 1;
      }
      if (cnt == n)
        continue;
      if (d[ticket][cn] < c.first)
        continue;

      for (int i = 1; i <= m; i++) {
        if (city[cn][i] != INF) {
          for (int j = 0; j < n; j++) {
            // j???????????¬???????????£??????????????£??????
            if (!((ticket >> j) & 1)) {
              double time = c.first + (city[cn][i] / (double)t[j]);
              unsigned tmp = ticket | (1 << j);
              if (d[tmp][i] > time) {
                d[tmp][i] = time;
                que.push(C(time, pci(tmp, i)));
              }
            }
          }
        }
      }
    }

    double ans = INF;
    for (int i = 0; i < 256; i++) {
      ans = min(ans, d[i][b]);
    }

    if (ans != INF) {
      printf("%.5f\\n", ans);
    } else {
      puts("Impossible");
    }
  }

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <utility>
#include <vector>

const int INF = (1 << 28);

using namespace std;

typedef pair<set<int>, int> psi;
typedef pair<double, set<int>> pds;
typedef pair<pds, psi>
    C; // ??????????????£?????´???????????£?????¬?????????????????´???

int main(void) {
  int n, m, p, a, b;

  while (cin >> n >> m >> p >> a >> b, n + m + p + a + b) {
    vector<int> t(n);
    for (int i = 0; i < n; i++) {
      cin >> t[i];
    }
    vector<vector<int>> city(m + 1, vector<int>(m + 1));
    for (int i = 0; i <= m; i++) {
      for (int j = 0; j <= m; j++) {
        city[i][j] = INF;
      }
    }

    int x, y, z;
    for (int i = 0; i < p; i++) {
      cin >> x >> y >> z;
      city[x][y] = z;
      city[y][x] = z;
    }

    bool flag = false;
    priority_queue<C, vector<C>, greater<C>> que;
    que.push(C(pds(0, set<int>()), psi(set<int>(), a)));
    while (!que.empty()) {
      C c = que.top();
      int cn = c.second.second; // ???????????????
      if (cn == b) {
        flag = true;
        break;
      }
      que.pop();
      set<int> vs = c.first.second; // ?????£?????´???
      if (vs.find(cn) != vs.end())
        continue;
      vs.insert(cn);
      set<int> cs = c.second.first; // ?????£???????????¬???
      if (cs.size() == n)
        continue;

      //            cout << "#: now: " << cn << endl;

      for (int i = 1; i <= m; i++) {
        if (city[cn][i] != INF) {
          for (int j = 0; j < n; j++) {
            // j???????????¬???????????£??????????????£??????
            if (cs.find(j) == cs.end()) {
              cs.insert(j);
              double dist = city[cn][i];
              //                            cout << "#: time, " <<
              //                            (c.first.first+dist)/t[j] << " " <<
              //                            cn << "->" << i << endl;
              que.push(C(pds(c.first.first + dist / t[j], vs), psi(cs, i)));
              cs.erase(j);
            }
          }
        }
      }
    }

    if (flag) {
      double ans = que.top().first.first;
      printf("%.5f\\n", ans);
    } else {
      printf("Impossible\\n");
    }
  }

  return 0;
}