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

#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define INF 100000000

struct P {
  int from;
  int used;
  double cost;

  bool operator>(const P &p) const { return cost > p.cost; }
};

struct Edge {
  int to, cost;
};

double G[30][256];

int main() {
  int ticket_n, town_n, road_n, start, goal;
  while (cin >> ticket_n >> town_n >> road_n >> start >> goal,
         ticket_n | town_n | road_n | start | goal) {
    start--;
    goal--;
    vi tickets(ticket_n);
    REP(i, ticket_n) cin >> tickets[i];
    vector<vector<Edge>> E(town_n);
    REP(i, road_n) {
      int x, y, z;
      cin >> x >> y >> z;
      x--;
      y--;
      E[x].push_back({y, z});
      E[y].push_back({x, z});
    }

    fill_n((double *)G, 30 * 256, INF);

    priority_queue<P, vector<P>, greater<P>> que;
    que.push({start, 0, 0});
    G[start][0] = 0;
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      if (p.from == goal) {
        printf("%.3f\\n", p.cost);
        goto END;
      }

      for (Edge e : E[p.from]) {
        REP(i, ticket_n) {
          if (!BIT(p.used, i)) {
            int used = p.used | (1 << i);
            double cost = p.cost + e.cost / (double)tickets[i];
            if (G[e.to][used] > cost) {
              G[e.to][used] = cost;
              que.push({e.to, used, cost});
            }
          }
        }
      }
    }
    cout << "Impossible" << endl;
  END : {}
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

// #define LOG(...) printf(__VA_ARGS__)
#define LOG(...)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define INF INT_MAX

struct edge {
  int to, cost;
};

typedef tuple<int, vector<pii>> P; // town, es(cost, town);
typedef vector<pii> ves;

int main() {
  int ticket_n, town_n, road_n, start, goal;
  // ifstream cin("data");
  while (cin >> ticket_n >> town_n >> road_n >> start >> goal,
         ticket_n | town_n | road_n | start | goal) {
    vi tickets(ticket_n);
    REP(i, ticket_n) { cin >> tickets[i]; }
    sort(RALL(tickets));

    vector<vector<edge>> G(town_n + 1);
    REP(i, road_n) {
      int from, to, cost;
      cin >> from >> to >> cost;
      G[from].push_back((edge){to, cost});
      G[to].push_back((edge){from, cost});
    }

    double min_time = INF;

    vi d(town_n + 1, INF);
    d[start] = 0;

    priority_queue<P, vector<P>, greater<P>> que;
    ves es_copy;
    que.push(P(start, es_copy));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      int v = get<0>(p);
      ves es = get<1>(p); // copy

      if (v == goal) {
        // ticket~~~
        double time = 0;
        sort(RALL(es));
        if (es.size() <= ticket_n) {
          REP(i, es.size()) {
            if (i < ticket_n) {
              time += (double)es[i].first / (double)tickets[i];
            } else {
              time += (double)es[i].first;
            }
            LOG("%d / %d, ", es[i].second, tickets[i]);
          }
          LOG(" -> %f\\n", min_time);
          min_time = min(min_time, time);
        }
      }

      REP(i, G[v].size()) {
        edge e = G[v][i];

        bool update = false;
        if (es.size() <= ticket_n) {
          update = true;
          REP(i, es.size()) {
            if (es[i].second == e.to) {
              update = false;
              break;
            }
          }
        }
        if (update) {
          vector<pii> es2 = es;
          es2.push_back({e.cost, e.to});
          que.push(P(e.to, es2));
        }
      }
    }
    if (min_time != INF) {
      printf("%0.3f\\n", min_time);
    } else {
      printf("Impossible\\n");
    }
  }
}