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

#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define INF 100000000.0
using namespace std;
struct state {
  int n, v, l;
  double t;
};

int N, M, S, G;
int vd[3] = {-1, 0, 1};

class Compare {
public:
  bool operator()(struct state a, struct state b) { return a.t > b.t; }
};

int main(void) {
  while (cin >> N >> M, N) {
    cin >> S >> G;

    vector<int> T[101], D[101], C[101];
    REP(i, 1, M) {
      int x, y, d, c;
      cin >> x >> y >> d >> c;
      T[x].push_back(y);
      D[x].push_back(d);
      C[x].push_back(c);
      T[y].push_back(x);
      D[y].push_back(d);
      C[y].push_back(c);
    }

    double dp[101][101][101];
    REP(i, 0, 100) REP(j, 0, 100) REP(k, 0, 100) dp[i][j][k] = INF;

    priority_queue<struct state, vector<struct state>, Compare> q;
    struct state first = {S, 0, -1, 0.0};
    q.push(first);

    while (!q.empty()) {
      struct state c = q.top();
      q.pop();

      // cout << c.n << " " << c.v << " " << c.t << endl;

      if (dp[c.n][c.l][c.v] <= c.t)
        continue;
      dp[c.n][c.l][c.v] = min(dp[c.n][c.l][c.v], c.t);

      for (int i = 0; i < T[c.n].size(); i++) {
        if (T[c.n][i] == c.l)
          continue;
        for (int j = 0; j < 3; j++) {
          int v = c.v + vd[j];
          if (v <= 0 || C[c.n][i] < v)
            continue;
          double t = c.t + ((double)D[c.n][i] / v);
          struct state n = {T[c.n][i], v, c.n, t};
          // if(n.t < dp[n.n][n.v]) q.push(n);
          q.push(n);
        }
      }
    }

    double ret = INF;
    REP(i, 1, N) ret = min(ret, dp[G][i][1]);
    if (ret < INF)
      printf("%.6f\\n", ret);
    else
      cout << "unreachable" << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define INF 100000000.0
using namespace std;
struct state {
  int n, v, l;
  double t;
};

int N, M, S, G;
vector<int> T[101], D[101], C[101];
int vd[3] = {-1, 0, 1};
double dp[101][101];

class Compare {
public:
  bool operator()(struct state a, struct state b) { return a.t > b.t; }
};

int main(void) {
  while (cin >> N >> M, N) {
    cin >> S >> G;
    REP(i, 0, 100) {
      T[i].clear();
      D[i].clear();
      C[i].clear();
    }
    REP(i, 1, M) {
      int x, y, d, c;
      cin >> x >> y >> d >> c;
      T[x].push_back(y);
      D[x].push_back(d);
      C[x].push_back(c);
      T[y].push_back(x);
      D[y].push_back(d);
      C[y].push_back(c);
    }

    REP(i, 1, N) REP(j, 0, 100) dp[i][j] = INF;

    priority_queue<struct state, vector<struct state>, Compare> q;
    struct state first = {S, 0, -1, 0.0};
    q.push(first);

    while (!q.empty()) {
      struct state c = q.top();
      q.pop();

      // cout << c.n << " " << c.v << " " << c.t << endl;

      if (dp[c.n][c.v] <= c.t)
        continue;
      dp[c.n][c.v] = min(dp[c.n][c.v], c.t);
      if (c.n == G && c.v == 1)
        break;

      for (int i = 0; i < T[c.n].size(); i++) {
        if (T[c.n][i] == c.l)
          continue;
        REP(j, 0, 3) {
          int v = c.v + vd[j];
          if (v <= 0 || C[c.n][i] < v)
            continue;
          double t = c.t + ((double)D[c.n][i] / v);
          struct state n = {T[c.n][i], v, c.n, t};
          if (n.t < dp[n.n][n.v])
            q.push(n);
        }
      }
    }

    if (dp[G][1] < INF)
      printf("%.6f\\n", dp[G][1]);
    else
      cout << "unreachable" << endl;
  }

  return 0;
}