alexjercan/bugnet huggingface dataset:
Problem p02243 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>

static const int MAX = 10000;
static const int INFTY = (1 << 20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

void dijkstra(int n, std::vector<std::pair<int, int>> adj[MAX]) {
  std::priority_queue<std::pair<int, int>> PQ;
  int color[MAX];
  int d[MAX];
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  PQ.push(std::make_pair(0, 0));
  color[0] = GRAY;

  while (!PQ.empty()) {
    std::pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.second;
    color[u] = BLACK;

    //????°???????????????????????????????????????§???????????°??????
    if (d[u] < f.first * (-1))
      continue;

    for (size_t i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i].first;
      if (color[v] == BLACK)
        continue;
      if (d[v] > d[u] + adj[u][i].second) {
        d[v] = d[u] + adj[u][i].second;
        // priority_queue????????????????????§??§??????????????????????????????-1????????????
        PQ.push(std::make_pair(d[v] * -1, v));
        color[v] = GRAY;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    std::cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << std::endl;
  }
}

int main() {
  std::vector<std::pair<int, int>> adj[MAX];
  int n;

  std::cin >> n;
  for (int i = 0; i < n; i++) {
    int u, k;
    std::cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int v, c;
      std::cin >> v >> c;
      adj[u].push_back(std::make_pair(v, c));
    }
  }

  dijkstra(n, adj);

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stack>
#include <vector>

#define INF (1 << 21)

int main() {
  int node_num;

  std::cin >> node_num;
  std::vector<std::vector<int>> node(node_num, std::vector<int>(node_num, -1));

  for (size_t i = 0; i < node.size(); i++) {
    int out, node_number;
    std::cin >> node_number >> out;
    for (int j = 0; j < out; j++) {
      int to, distance;
      std::cin >> to >> distance;
      node[node_number][to] = distance;
    }
  }

  std::vector<int> distance(node.size(), INF);
  std::stack<int> s;
  distance[0] = 0;

  s.push(0);
  while (!s.empty()) {
    int node_number = s.top();
    s.pop();
    for (size_t j = 0; j < node[node_number].size(); j++) {
      if (node[node_number][j] != -1 &&
          node[node_number][j] + distance[node_number] < distance[j]) {
        distance[j] = node[node_number][j] + distance[node_number];
        s.push(j);
      }
    }
  }

  for (size_t i = 0; i < distance.size(); i++) {
    std::cout << i << " " << distance[i] << std::endl;
  }
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <limits>
#include <queue>
#include <vector>
using namespace std;

struct vec {
  int t, c;
  vec(int to, int cost) : t(to), c(cost) {}
  bool operator>(const vec &r) const { return t > r.t; }
};
vector<vec> adj[10000];
int d[10000];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    d[i] = numeric_limits<int>::max();
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    adj[u].reserve(k);
    for (int j = 0; j < k; j++) {
      int v, c;
      cin >> v >> c;
      adj[u].push_back(vec(v, c));
    }
  }
  priority_queue<vec, vector<vec>, greater<vec>> q;
  q.push(vec(0, 0));
  while (!q.empty()) {
    vec e = q.top();
    q.pop();
    if (d[e.t] <= e.c)
      continue;
    d[e.t] = e.c;
    for (vector<vec>::iterator it = adj[e.t].begin(); it != adj[e.t].end();
         ++it)
      q.push(vec(it->t, e.c + it->c));
  }
  for (int i = 0; i < n; i++)
    cout << i << ' ' << d[i] << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <limits>
#include <queue>
using namespace std;

struct vec {
  int t, c;
  vec(int to, int cost) : t(to), c(cost) {}
  bool operator>(const vec &r) const { return t > r.t; }
};
vector<vec> adj[100];
int d[100];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    d[i] = numeric_limits<int>::max();
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    adj[u].reserve(k);
    for (int j = 0; j < k; j++) {
      int v, c;
      cin >> v >> c;
      adj[u].push_back(vec(v, c));
    }
  }
  priority_queue<vec, vector<vec>, greater<vec>> q;
  q.push(vec(0, 0));
  while (!q.empty()) {
    vec e = q.top();
    q.pop();
    if (d[e.t] <= e.c)
      continue;
    d[e.t] = e.c;
    for (vector<vec>::iterator it = adj[e.t].begin(); it != adj[e.t].end();
         ++it)
      q.push(vec(it->t, e.c + it->c));
  }
  for (int i = 0; i < n; i++)
    cout << i << ' ' << d[i] << '\\n';
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

struct Edge {
  int to, weight;
};

int main() {
  int n, u, k, v, c, distance[100000]{}, upd_num = 1;
  bool must_update[100000]{1};
  std::vector<Edge> dest[500000];

  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::cin >> u >> k;
    for (int j = 0; j < k; ++j) {
      std::cin >> v >> c;
      dest[u].push_back({v, c});
    }
    if (i)
      distance[i] = 2000000000;
  }

  while (upd_num)
    for (int i = 0; i < n && upd_num; i++) {
      if (!must_update[i])
        continue;

      must_update[i] = false;
      upd_num--;
      for (auto e : dest[i]) {
        int tmp = distance[i] + e.weight;
        if (tmp < distance[e.to]) {
          distance[e.to] = tmp;
          if (!must_update[e.to]) {
            must_update[e.to] = true;
            upd_num++;
          }
        }
      }
    }

  for (int i = 0; i < n; i++) {
    std::cout << i << " " << distance[i] << std::endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>

struct Edge {
  int to, weight;
};

int main() {
  int n, u, k, v, c, distance[100]{}, upd_num = 1;
  bool must_update[100]{1};
  std::vector<Edge> dest[100];

  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    std::cin >> u >> k;
    for (int j = 0; j < k; ++j) {
      std::cin >> v >> c;
      dest[u].push_back({v, c});
    }
    if (i)
      distance[i] = 2000000000;
  }

  while (upd_num)
    for (int i = 0; i < n && upd_num; i++) {
      if (!must_update[i])
        continue;

      must_update[i] = false;
      upd_num--;
      for (auto e : dest[i]) {
        int tmp = distance[i] + e.weight;
        if (tmp < distance[e.to]) {
          distance[e.to] = tmp;
          if (!must_update[e.to]) {
            must_update[e.to] = true;
            upd_num++;
          }
        }
      }
    }

  for (int i = 0; i < n; i++) {
    std::cout << i << " " << distance[i] << std::endl;
  }

  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define rep(index, num) for (int index = 0; index < num; index++)
#define rep1(index, num) for (int index = 1; index <= num; index++)
#define scan(argument) cin >> argument
#define prin(argument) cout << argument << endl
#define kaigyo cout << endl
#define eps 1e-15
#define mp(a1, a2) make_pair(a1, a2)
typedef long long ll;
using namespace std;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
int INF = 1e+9 + 1;
int N;
vpint adj[10000];
int d[10000], color[10000], p[10000];
void dijkstra() {
  priority_queue<pint> PQ;
  rep(i, N) {
    d[i] = INF;
    color[i] = 0;
  }
  d[0] = 0;
  color[0] = 1;
  PQ.push(mp(0, 0));
  while (!PQ.empty()) {
    pint f = PQ.top();
    PQ.pop();
    int u = f.second;
    color[u] = 2;
    if (d[u] < -f.first)
      continue;
    rep(j, adj[u].size()) {
      int v = adj[u][j].first;
      if (color[v] == 2)
        continue;
      if (d[v] > d[u] + adj[u][j].second) {
        d[v] = d[u] + adj[u][j].second;
        PQ.push(mp(-d[v], v));
        color[v] = 1;
      }
    }
  }
}
int main() {
  scan(N);
  int k, c, u, v;
  rep(i, N) {
    scan(u);
    scan(k);
    rep(j, k) {
      scan(v);
      scan(c);
      adj[u].push_back(mp(v, c));
    }
  }
  dijkstra();
  rep(i, N) { printf("%d %d\\n", i, (d[i] == INF ? -1 : d[i])); }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define rep(index, num) for (int index = 0; index < num; index++)
#define rep1(index, num) for (int index = 1; index <= num; index++)
#define scan(argument) cin >> argument
#define prin(argument) cout << argument << endl
#define kaigyo cout << endl
#define eps 1e-15
#define mp(a1, a2) make_pair(a1, a2)
typedef long long ll;
using namespace std;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
int INF = 1e+9 + 1;
int N;
vpint adj[10000];
int d[100], color[100], p[100];
void dijkstra() {
  priority_queue<pint> PQ;
  rep(i, N) {
    d[i] = INF;
    color[i] = 0;
  }
  d[0] = 0;
  color[0] = 1;
  PQ.push(mp(0, 0));
  while (!PQ.empty()) {
    pint f = PQ.top();
    PQ.pop();
    int u = f.second;
    color[u] = 2;
    if (d[u] < -f.first)
      continue;
    rep(j, adj[u].size()) {
      int v = adj[u][j].first;
      if (color[v] == 2)
        continue;
      if (d[v] > d[u] + adj[u][j].second) {
        d[v] = d[u] + adj[u][j].second;
        PQ.push(mp(-d[v], v));
        color[v] = 1;
      }
    }
  }
}
int main() {
  scan(N);
  int k, c, u, v;
  rep(i, N) {
    scan(u);
    scan(k);
    rep(j, k) {
      scan(v);
      scan(c);
      adj[u].push_back(mp(v, c));
    }
  }
  dijkstra();
  rep(i, N) { printf("%d %d\\n", i, (d[i] == INF ? -1 : d[i])); }
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MAX 10000
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY (1 << 30)
int n;
vector<pair<int, int>> adj[MAX];

void dijkstra() {
  priority_queue<pair<int, int>> PQ;
  int d[MAX], color[MAX];
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
    color[i] = WHITE;
  }
  d[0] = 0;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;
  while (!PQ.empty()) {
    pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.second;
    color[u] = BLACK;
    if (d[u] < f.first * (-1))
      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] * (-1), v));
        color[v] = GRAY;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main() {
  cin >> n;

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

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY (1 << 30)
int n;
vector<pair<int, int>> adj[MAX];

void dijkstra() {
  priority_queue<pair<int, int>> PQ;
  int d[MAX], color[MAX];
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
    color[i] = WHITE;
  }
  d[0] = 0;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;
  while (!PQ.empty()) {
    pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.second;
    color[u] = BLACK;
    if (d[u] < f.first * (-1))
      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] * (-1), v));
        color[v] = GRAY;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main() {
  cin >> n;

  int k, c, u, v;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      adj[u].push_back(make_pair(v, c));
    }
  }
  dijkstra();
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)

#define mp make_pair
#define P pair<int, int>
#define ll __int64
vector<P> G[20000];
int n, u, k;
const int INF = 100000000;
int ans[20000];

int main() {
  int from, cost;
  cin >> n;

  rep(i, n) {
    cin >> u >> k;
    rep(i, k) {
      cin >> from >> cost;
      G[u].push_back(mp(from, cost));
    }
  }
  rep(i, n) ans[i] = INF;
  // ans[0]=0;
  priority_queue<P, vector<P>, greater<P>>
      que; // firstスタートからの重みsecond頂点
  que.push(mp(0, 0));

  while (!que.empty()) {
    P now = que.top();
    que.pop();
    if (ans[now.second] != INF)
      continue;
    int index = now.second;
    ans[index] = now.first;
    // cout<<now.first<<endl;
    for (int i = 0; i < G[now.second].size(); i++)
      que.push(mp(now.first + G[index][i].second,
                  G[index][i].first)); // 次への経路長、頂点番号
  }
  for (int i = 0; i < n; i++)
    cout << i << " " << ans[i] << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)

#define mp make_pair
#define P pair<int, int>
#define ll __int64
vector<P> G[10000];
int n, u, k;
const int INF = 100000000;
int ans[1000];

int main() {
  int from, cost;
  cin >> n;

  rep(i, n) {
    cin >> u >> k;
    rep(i, k) {
      cin >> from >> cost;
      G[u].push_back(mp(from, cost));
    }
  }
  rep(i, n) ans[i] = INF;
  // ans[0]=0;
  priority_queue<P, vector<P>, greater<P>>
      que; // firstスタートからの重みsecond頂点
  que.push(mp(0, 0));

  while (!que.empty()) {
    P now = que.top();
    que.pop();
    if (ans[now.second] != INF)
      continue;
    int index = now.second;
    ans[index] = now.first;
    // cout<<now.first<<endl;
    for (int i = 0; i < G[now.second].size(); i++)
      que.push(mp(now.first + G[index][i].second,
                  G[index][i].first)); // 次への経路長、頂点番号
  }
  for (int i = 0; i < n; i++)
    cout << i << " " << ans[i] << endl;
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <climits>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
using namespace std;

typedef map<int, int>::iterator mitr;

map<int, int> w[10000];
int d[10000];
char pos[10000];

priority_queue<pair<int, int>> others;
pair<int, int> p;

void findPath() {
  p = others.top();
  others.pop();
  while (pos[p.second]) {
    p = others.top();
    others.pop();
  }
  pos[p.second] = 1;

  int tmpu = p.second;
  int tmpd = -p.first;

  for (mitr i = w[tmpu].begin(); i != w[tmpu].end(); i++) {
    if (tmpd + i->second < d[i->first]) {
      d[i->first] = tmpd + i->second;
      others.push(make_pair(-d[i->first], i->first));
    }
  }
}

int main() {
  int i, j, u, k, n, v, c;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &u, &k);
    for (j = 0; j < k; j++) {
      scanf("%d %d", &v, &c);
      w[u][v] = c;
    }
  }

  memset(pos, 0, sizeof(char) * 100);
  for (i = 0; i < n; i++)
    d[i] = INT_MAX;
  d[0] = 0;
  others.push(make_pair(0, 0));
  for (i = 0; i < n; i++)
    findPath();
  for (i = 0; i < n; i++)
    printf("%d %d\\n", i, d[i]);

  return 0;
}


Error: 0

Fixed submission:

#include <climits>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
using namespace std;

typedef map<int, int>::iterator mitr;

map<int, int> w[100];
int d[100];
char pos[100];

priority_queue<pair<int, int>> others;
pair<int, int> p;

void findPath() {
  p = others.top();
  others.pop();
  while (pos[p.second]) {
    p = others.top();
    others.pop();
  }
  pos[p.second] = 1;

  int tmpu = p.second;
  int tmpd = -p.first;

  for (mitr i = w[tmpu].begin(); i != w[tmpu].end(); i++) {
    if (tmpd + i->second < d[i->first]) {
      d[i->first] = tmpd + i->second;
      others.push(make_pair(-d[i->first], i->first));
    }
  }
}

int main() {
  int i, j, u, k, n, v, c;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &u, &k);
    for (j = 0; j < k; j++) {
      scanf("%d %d", &v, &c);
      w[u][v] = c;
    }
  }

  memset(pos, 0, sizeof(char) * 100);
  for (i = 0; i < n; i++)
    d[i] = INT_MAX;
  d[0] = 0;
  others.push(make_pair(0, 0));
  for (i = 0; i < n; i++)
    findPath();
  for (i = 0; i < n; i++)
    printf("%d %d\\n", i, d[i]);

  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

// ALDS1_12_C.cpp
// Graph II - Single Source Shortest Path II
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

struct Node {
  int v;
  int c;
  Node(int v, int c) : v(v), c(c) {}
};

const int maxN = 10000;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INF = (1 << 21);
vector<Node> G[maxN];
vector<int> dist(maxN, INF);
vector<int> p(maxN);
vector<int> color(maxN, WHITE);
priority_queue<pair<int, int>> mq;
int n;

void dijkstra(int x) {
  dist[x] = 0;
  p[x] = -1;
  mq.push({-dist[x], x});
  while (!mq.empty()) {
    pair<int, int> P = mq.top();
    mq.pop();
    int mindist = -P.first;
    int u = P.second;
    if (color[u] == BLACK)
      continue;

    for (int i = 0; i < G[u].size(); i++) {
      if (color[u] == BLACK)
        continue;
      int v = G[u][i].v;
      int c = G[u][i].c;
      if (dist[u] + c < dist[v]) {
        dist[v] = dist[u] + c;
        p[v] = u;
        color[v] = GRAY;
        mq.push({-dist[v], v});
      }
    }
    color[u] = BLACK;
  }
}

int main() {
  //    freopen("in7.txt", "r", stdin);
  //    freopen("out7.txt", "w", stdout);
  cin >> n;
  int u, k;
  int v, c;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      G[i].push_back(Node(v, c));
    }
  }
  dijkstra(0);
  for (int i = 0; i < n; i++) {
    printf("%d %d\\n", i, dist[i]);
  }
  return 0;
}

Error: 0

Fixed submission:

// ALDS1_12_C.cpp
// Graph II - Single Source Shortest Path II
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

struct Node {
  int v;
  int c;
  Node(int v, int c) : v(v), c(c) {}
};

const int maxN = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INF = (1 << 21);
vector<Node> G[maxN];
vector<int> dist(maxN, INF);
vector<int> p(maxN);
vector<int> color(maxN, WHITE);
int n;
int cnt = 0;
void dijkstra(int x) {
  dist[x] = 0;
  p[x] = -1;
  while (++cnt != n) {
    int u = 0;
    int mindist = INF;
    for (int i = 0; i < n; i++) {
      if (color[i] != BLACK && dist[i] < mindist) {
        mindist = dist[i];
        u = i;
      }
    }

    for (int i = 0; i < G[u].size(); i++) {
      if (color[u] == BLACK)
        continue;
      int v = G[u][i].v;
      int c = G[u][i].c;
      if (dist[u] + c < dist[v]) {
        dist[v] = dist[u] + c;
        p[v] = u;
        color[v] = GRAY;
      }
    }
    color[u] = BLACK;
  }
}

int main() {
  cin >> n;
  int u, k;
  int v, c;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      G[i].push_back(Node(v, c));
    }
  }
  dijkstra(0);
  for (int i = 0; i < n; i++) {
    printf("%d %d\\n", i, dist[i]);
  }
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

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

void dijkstra() {
  priority_queue<pair<int, int>> PQ;
  int d[MAX], color[MAX];

  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;
  while (!PQ.empty()) {
    pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.second;

    color[u] = BLACK;

    if (d[u] < f.first * (-1))
      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] * (-1), v));
        color[v] = GRAY;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main() {
  int k, c, u, v;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      adj[u].push_back(make_pair(v, c));
    }
  }

  dijkstra();

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

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

void dijkstra() {
  priority_queue<pair<int, int>> PQ;
  int d[MAX], color[MAX];

  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;
  while (!PQ.empty()) {
    pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.second;

    color[u] = BLACK;

    if (d[u] < f.first * (-1))
      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] * (-1), v));
        color[v] = GRAY;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main() {
  int k, c, u, v;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      adj[u].push_back(make_pair(v, c));
    }
  }

  dijkstra();

  return 0;
}