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

#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define fr first
#define sc second
#define mp make_pair
#define INF (2 << 28)
using namespace std;

typedef pair<int, int> iP;
struct node {
  int cost, pass;
  vector<int> rd, edge;
};

int n, k, costed[5001];
bool used[5001];
vector<node> info(5001);

void init() {
  for (int i = 0; i < 5001; i++)
    costed[i] = INF;
}

void make_graph() {
  queue<iP> que;
  for (int i = 1; i < n + 1; i++) {
    memset(used, 1, sizeof(used));
    que.push(mp(i, info[i].pass));
    while (!que.empty()) {
      iP p = que.front();
      que.pop();
      if (!p.sc)
        continue;
      for (int j = 0; j < info[p.fr].rd.size(); j++) {
        if (used[info[p.fr].rd[j]]) {
          used[info[p.fr].rd[j]] = 0;
          que.push(mp(info[p.fr].rd[j], p.sc - 1));
          info[i].edge.push_back(info[p.fr].rd[j]);
        }
      }
    }
  }
}

int Dijkstra() {
  priority_queue<iP, vector<iP>, greater<iP>> que;
  que.push(mp(1, 0));
  while (!que.empty()) {
    iP p = que.top();
    que.pop();
    if (p.fr == n)
      return p.sc;
    for (int i = 0; i < info[p.fr].edge.size(); i++) {
      if (p.sc + info[p.fr].cost < costed[info[p.fr].edge[i]]) {
        que.push(mp(info[p.fr].edge[i], p.sc + info[p.fr].cost));
        costed[info[p.fr].edge[i]] = p.sc + info[p.fr].cost;
      }
    }
  }
}

int main() {
  cin >> n >> k;
  init();

  for (int i = 0; i < n; i++)
    cin >> info[i + 1].cost >> info[i + 1].pass;

  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    info[a].rd.push_back(b);
    info[b].rd.push_back(a);
  }

  make_graph();

  cout << Dijkstra() << endl;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define fr first
#define sc second
#define mp make_pair
#define INF (2 << 28)
using namespace std;

typedef pair<int, int> iP;
typedef pair<iP, int> iiP;
struct edge {
  int to, cost;
  edge() {}
  edge(int to, int cost) : to(to), cost(cost) {}
};

bool used[5001], aaa[5001][5001];
int n, k, costed[5001];
vector<vector<int>> road;
vector<iP> taxi;
vector<vector<edge>> info;

void init() {
  memset(aaa, true, sizeof(aaa));
  memset(used, true, sizeof(used));
  info.resize(n + 1);
  road.resize(k + 1);
  taxi.resize(n + 1);
  for (int i = 0; i < 5001; i++) {
    costed[i] = INF;
  }
}

void make_gragh() {
  queue<iiP> que;
  que.push(mp(mp(1, taxi[1].sc), 1));
  used[1] = false;
  while (!que.empty()) {
    iiP p = que.front();
    que.pop();
    int now = p.fr.fr, pass = p.fr.sc, srt = p.sc;
    for (int i = 0; i < road[now].size(); i++) {
      if (pass > 0) {
        que.push(mp(mp(road[now][i], pass - 1), srt));
        if (aaa[srt][road[now][i]]) {
          if (srt != road[now][i])
            info[srt].push_back(edge(road[now][i], taxi[srt].fr));
          aaa[srt][road[now][i]] = false;
        }
        if (used[now]) {
          used[now] = false;
          que.push(mp(mp(now, taxi[now].sc), now));
        }
      }
    }
  }
}

int Dijkstra() {
  priority_queue<iP, vector<iP>, greater<iP>> que;
  que.push(mp(1, 0));
  costed[1] = 0;
  while (!que.empty()) {
    iP p = que.top();
    que.pop();
    int now = p.fr, c = p.sc;
    if (now == n)
      return c;
    for (int i = 0; i < info[now].size(); i++) {
      edge e = info[now][i];
      if (e.cost + c < costed[e.to]) {
        que.push(mp(e.to, c + e.cost));
        costed[e.to] = c + e.cost;
      }
    }
  }
}

int main() {
  cin >> n >> k;

  init();

  for (int i = 0; i < n; i++)
    cin >> taxi[i + 1].fr >> taxi[i + 1].sc;

  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    road[a].push_back(b);
    road[b].push_back(a);
  }

  make_gragh();

  cout << Dijkstra() << endl;

  /*  for(int i=1;i<info.size();i++){
     cout << i << " : ";
     for(int j=0;j<info[i].size();j++){
     cout << info[i][j].to << " ";
     }
     cout << endl;
     }*/
}