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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX 10000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
vector<pair<int, int>> adj[MAX];

typedef pair<int, int> pii;

void dijkstra() {
  priority_queue<pii, vector<pii>, greater<pii>> PQ; // d[id] d
  int color[MAX] = {}, d[MAX];
  fill(d, d + MAX, INF);
  d[0] = 0;

  //?§????????????\\
	PQ.push(make_pair(0, 0));
  color[0] = GRAY;

  // PQ???????´????????????°
  while (!PQ.empty()) {
    // d????????§???(-????°????)??¨??????????´????????????????
    pii f = PQ.top();
    PQ.pop();

    int u = f.second;
    color[u] = BLACK;

    //????????§???????????°??????
    if (d[u] < f.first) {
      continue;
    }

    //??£??\\????????????????????¨????????????
    for (int j = 0; j < adj[u].size(); j++) {
      int v = adj[u][j].first;
      if (color[v] == BLACK)
        continue;
      if (d[v] > d[u] + adj[u][j].second) {
        d[v] = d[u] + adj[u][j].second;
        PQ.push(make_pair(d[v], v));
        color[v] = GRAY;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int u, k;
    scanf("%d%d", &u, &k);
    for (int j = 0; j < k; j++) {
      int v, c;
      scanf("%d%d", &v, &c);
      adj[u].push_back(make_pair(v, c));
    }
  }
  dijkstra();
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX 10000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
vector<pair<int, int>> adj[MAX];

typedef pair<int, int> pii;

void dijkstra() {
  priority_queue<pii, vector<pii>, greater<pii>> PQ; // d[id] d
  int color[MAX] = {}, d[MAX];
  fill(d, d + MAX, INF);
  d[0] = 0;

  //?§????????????\\
	PQ.push(make_pair(0, 0));
  color[0] = GRAY;

  // PQ???????´????????????°
  while (!PQ.empty()) {
    // d????????§???(-????°????)??¨??????????´????????????????
    pii f = PQ.top();
    PQ.pop();

    int u = f.second;
    color[u] = BLACK;

    //????????§???????????°??????
    if (d[u] < f.first) {
      continue;
    }

    //??£??\\????????????????????¨????????????
    for (int j = 0; j < adj[u].size(); j++) {
      int v = adj[u][j].first;
      if (color[v] == BLACK)
        continue;
      if (d[v] > d[u] + adj[u][j].second) {
        d[v] = d[u] + adj[u][j].second;
        PQ.push(make_pair(d[v], v));
        color[v] = GRAY;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int u, k;
    scanf("%d%d", u, k);
    for (int j = 0; j < k; j++) {
      int v, c;
      scanf("%d%d", v, c);
      adj[u].push_back(make_pair(v, c));
    }
  }
  dijkstra();
  return 0;
}