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

// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = 1e+5;

int N, M, P, A, B;
int T[10];
int cost[31][31];

int main() {
  while (true) {
    cin >> N >> M >> P >> A >> B;
    if (N == 0)
      break;
    --A, --B;
    REP(i, N) cin >> T[i];
    fill((int *)cost, (int *)cost + 31 * 31, -1);
    REP(i, P) {
      int a, b, c;
      cin >> a >> b >> c;
      --a, --b;
      cost[a][b] = cost[b][a] = c;
    }
    double dp[31][1 << 10];
    fill((double *)dp, (double *)dp + 31 * (1 << 10), INF);
    dp[A][(1 << N) - 1] = 0.0;

    for (int bit = (1 << N) - 1; bit >= 0; --bit) {
      for (int s = 0; s < M; ++s) {
        for (int u = 0; u < N; ++u) {
          if ((bit >> u & 1) == 0)
            continue;
          for (int to = 0; to < M; ++to) {
            if (cost[s][to] < 0)
              continue;
            dp[to][bit & ~(1 << u)] =
                min(dp[to][bit & ~(1 << u)],
                    dp[s][bit] + (double)cost[s][to] / T[u]);
          }
        }
      }
    }

    double ans = INF;
    for (int bit = 0; bit < (1 << N); ++bit)
      ans = min(ans, dp[B][bit]);
    if (ans == INF)
      cout << "Impossible" << endl;
    else
      printf("%.3lf\\n", ans);
  }
  return 0;
}

Error: WA

Fixed submission:

// include
//------------------------------------------
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

int N, M, P, A, B;
int T[10];
int cost[11][11];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  while (true) {
    cin >> N >> M >> P >> A >> B;
    if (N == 0)
      break;
    --A, --B;
    REP(i, N) cin >> T[i];
    fill((int *)cost, (int *)cost + 11 * 11, -1);
    REP(i, P) {
      int a, b, c;
      cin >> a >> b >> c;
      --a, --b;
      cost[a][b] = cost[b][a] = c;
    }
    double dp[11][1 << 10];
    fill((double *)dp, (double *)dp + 11 * (1 << 10), 1e+10);
    dp[A][(1 << N) - 1] = 0.;

    for (int bit = (1 << N) - 1; bit >= 0; --bit) {
      for (int s = 0; s < M; ++s) {
        for (int u = 0; u < N; ++u) {
          if (((bit >> u) & 1) == 0)
            continue;
          for (int to = 0; to < M; ++to) {
            if (cost[s][to] < 0)
              continue;
            dp[to][bit & ~(1 << u)] =
                min(dp[to][bit & ~(1 << u)],
                    dp[s][bit] + (double)cost[s][to] / T[u]);
          }
        }
      }
    }

    double ans = 1e+11;
    for (int bit = 0; bit < (1 << N); ++bit) {
      ans = min(ans, dp[B][bit]);
    }
    if (ans >= 1e+10)
      cout << "Impossible" << endl;
    else
      printf("%.6lf\\n", ans);
  }

  return 0;
}