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

#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int n, m;
typedef struct {
  int cost, limit;
  vector<int> node, taxi;
} edge;
edge info[5010];
bool used[5010];

int main() {
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> info[i].cost >> info[i].limit;
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    info[a].node.push_back(b);
    info[b].node.push_back(a);
  }

  queue<P> que;
  for (int i = 0; i < n; i++) {
    fill_n(used, 5001, false);
    // used[i] = true;
    que.push(P(i, info[i].limit));
    while (!que.empty()) {
      P p = que.front();
      que.pop();
      int now = p.first;
      int dis = p.second;
      if (dis == 0)
        continue;
      int len = info[now].node.size();
      for (int j = 0; j < len; j++) {
        int next = info[now].node[j];
        if (!used[next]) {
          used[next] = true;
          info[i].taxi.push_back(info[now].node[j]);
          que.push(P(info[now].node[j], dis - 1));
        }
      }
    }
  }

  priority_queue<P, vector<P>, greater<P>> que1;
  que1.push(P(0, 0));
  fill_n(used, 5001, false);
  while (!que1.empty()) {
    P p = que1.top();
    que1.pop();
    int c = p.first;
    int now = p.second;
    if (used[now])
      continue;
    used[now] = true;
    if (now == n - 1) {
      cout << c << endl;
      break;
    }
    int len = info[now].taxi.size();
    for (int j = 0; j < len; j++) {
      int next = info[now].taxi[j];
      que1.push(P(c + info[now].cost, next));
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;
int n, m;
typedef struct {
  int cost, limit;
  vector<int> node, taxi;
} edge;
edge info[5010];
bool used[5010];

int main() {
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> info[i].cost >> info[i].limit;
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    info[a].node.push_back(b);
    info[b].node.push_back(a);
  }
  queue<P> que;
  for (int i = 0; i < n; i++) {
    fill_n(used, 5001, false);
    used[i] = true;
    que.push(P(i, info[i].limit));
    while (!que.empty()) {
      P p = que.front();
      que.pop();
      int now = p.first;
      int dis = p.second;
      if (dis == 0)
        continue;
      int len = info[now].node.size();
      for (int j = 0; j < len; j++) {
        int next = info[now].node[j];
        if (!used[next]) {
          used[next] = true;
          info[i].taxi.push_back(info[now].node[j]);
          que.push(P(info[now].node[j], dis - 1));
        }
      }
    }
  }

  priority_queue<P, vector<P>, greater<P>> que1;
  que1.push(P(0, 0));
  fill_n(used, 5001, false);
  while (!que1.empty()) {
    P p = que1.top();
    que1.pop();
    int c = p.first;
    int now = p.second;
    if (used[now])
      continue;
    if (now == n - 1) {
      cout << c << endl;
      break;
    }
    int len = info[now].taxi.size();
    for (int j = 0; j < len; j++) {
      int next = info[now].taxi[j];
      que1.push(P(c + info[now].cost, next));
    }
  }
}