alexjercan/bugnet huggingface dataset:
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <stdio.h>
#include <tuple>
#include <vector>
using namespace std;

#define NUM 10000
#define NIL -1
#define INF 1000000000
#define WHITE 0
#define BLACK 1
int node_num;
vector<tuple<int, int>> G[NUM];
priority_queue<tuple<int, int>> PQ;
int V[NUM];
int color[NUM];

void init(void) {
  scanf("%d", &node_num);

  for (int i = 0; i < node_num; i++) {
    int u, k;
    scanf("%d", &u);
    scanf("%d", &k);

    for (int j = 0; j < k; j++) {
      int v_, c;
      scanf("%d", &v_);
      scanf("%d", &c);
      G[u].push_back(make_tuple(v_, c));
    }
  }

  for (int i = 0; i < node_num; i++) {
    color[i] = WHITE;
    V[i] = INF;
  }
}

void updateAround(int n) {
  color[n] = BLACK;
  for (int i = 0; i < G[n].size(); i++) {
    int old_dist = V[get<0>(G[n][i])];
    int new_dist = V[n] + get<1>(G[n][i]);
    if (new_dist < old_dist) {
      V[get<0>(G[n][i])] = new_dist;
      PQ.push(make_tuple(-new_dist, get<0>(G[n][i])));
    }
  }

  int min_index = NIL;
  int min_value = INF;
  while (!PQ.empty()) {
    tuple<int, int> f = PQ.top();
    PQ.pop();
    if (color[get<1>(f)] == BLACK) {
      continue;
    }
    min_value = -get<0>(f);
    min_index = get<1>(f);
    break;
  }

  if (min_index != NIL) {
    updateAround(min_index);
  }
}

int main(void) {
  init();

  V[0] = 0;
  updateAround(0);

  for (int i = 0; i < node_num; i++) {
    printf("%d %d\\n", i, V[i]);
  }
}


Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <stdio.h>
#include <tuple>
#include <vector>
using namespace std;

#define NUM 100
#define NIL -1
#define INF 1000000000
#define WHITE 0
#define BLACK 1
int node_num;
vector<tuple<int, int>> G[NUM];
priority_queue<tuple<int, int>> PQ;
int V[NUM];
int color[NUM];

void init(void) {
  scanf("%d", &node_num);

  for (int i = 0; i < node_num; i++) {
    int u, k;
    scanf("%d", &u);
    scanf("%d", &k);

    for (int j = 0; j < k; j++) {
      int v_, c;
      scanf("%d", &v_);
      scanf("%d", &c);
      G[u].push_back(make_tuple(v_, c));
    }
  }

  for (int i = 0; i < node_num; i++) {
    color[i] = WHITE;
    V[i] = INF;
  }
}

void updateAround(int n) {
  color[n] = BLACK;
  for (int i = 0; i < G[n].size(); i++) {
    int old_dist = V[get<0>(G[n][i])];
    int new_dist = V[n] + get<1>(G[n][i]);
    if (new_dist < old_dist) {
      V[get<0>(G[n][i])] = new_dist;
      PQ.push(make_tuple(-new_dist, get<0>(G[n][i])));
    }
  }

  int min_index = NIL;
  int min_value = INF;
  while (!PQ.empty()) {
    tuple<int, int> f = PQ.top();
    PQ.pop();
    if (color[get<1>(f)] == BLACK) {
      continue;
    }
    min_value = -get<0>(f);
    min_index = get<1>(f);
    break;
  }

  if (min_index != NIL) {
    updateAround(min_index);
  }
}

int main(void) {
  init();

  V[0] = 0;
  updateAround(0);

  for (int i = 0; i < node_num; i++) {
    printf("%d %d\\n", i, V[i]);
  }
}
Problem p02243 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

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;

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

void dijkstra() {
  priority_queue<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(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, u, v, c;

  // cout << "testing" << endl;

  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: MLE

Fixed submission:

#include <iostream>
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, M[MAX][MAX];

void dijkstra() {
  int minv;
  int d[MAX], color[MAX];

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

  d[0] = 0;
  // color[0] = GRAY;
  while (1) {
    minv = INFTY;
    int u = -1;
    for (int i = 0; i < n; i++) {
      if (minv > d[i] && color[i] != BLACK) {
        u = i;
        minv = d[i];
      }
    }
    if (u == -1)
      break;
    color[u] = BLACK;
    for (int v = 0; v < n; v++) {
      if (color[v] != BLACK && M[u][v] != INFTY) {
        if (d[v] > d[u] + M[u][v]) {
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i << " " << d[i] << endl;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      M[i][j] = INFTY;
    }
  }

  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;
      M[u][v] = c;
    }
  }

  dijkstra();
}
Problem p02243 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <queue>
#include <vector>
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 color[MAX];
  int d[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, u, v, c;
  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: MLE

Fixed submission:

#include <iostream>
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, M[MAX][MAX];

void dijkstra() {
  int minv;
  int d[MAX], color[MAX];

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

  d[0] = 0;
  // color[0] = GRAY;
  while (1) {
    minv = INFTY;
    int u = -1;
    for (int i = 0; i < n; i++) {
      if (minv > d[i] && color[i] != BLACK) {
        u = i;
        minv = d[i];
      }
    }
    if (u == -1)
      break;
    color[u] = BLACK;
    for (int v = 0; v < n; v++) {
      if (color[v] != BLACK && M[u][v] != INFTY) {
        if (d[v] > d[u] + M[u][v]) {
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i << " " << d[i] << endl;
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      M[i][j] = INFTY;
    }
  }

  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;
      M[u][v] = c;
    }
  }

  dijkstra();
}
Problem p02243 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#define INF 1 << 30
#define FinishFunction return 0
#define MAX 1000000
using namespace std;

struct edge {
  int from, to, cost, k;
};

edge es[MAX];

int main() {
  int n, u, k, E, c, v;
  E = 0;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d %d", &u, &k);

    for (int j = 0; j < k; j++) {
      scanf("%d %d", &v, &c);
      es[E].from = u;
      es[E].to = v;
      es[E++].cost = c;
    }
  }

  // Ika berumanfo-do
  int d[MAX];
  for (int i = 0; i < n; i++)
    d[i] = INF;
  d[0] = 0;
  while (true) {
    bool update = false;
    for (int i = 0; i < E; i++) {
      edge e = es[i];
      if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if (!update)
      break;
  }
  for (int i = 0; i < n; i++)
    cout << i << " " << d[i] << endl;
  FinishFunction; // return 0
}

Error: TLE

Fixed submission:

#include <iostream>
int main() {
  int u, k, C, V, A[1000][1000], D[1000][1000], n;
  std::cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      D[i][j] = 200001;
  for (int i = 0; i < n; i++) {
    std::cin >> u >> k;
    for (int j = 0; j < k; j++) {
      std::cin >> V >> C;
      D[u][V] = C;
    }
  }
  for (int i = 0; i < n; i++)
    D[i][i] = 0;
  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        D[i][j] = std::min(D[i][j], D[i][k] + D[k][j]);
  for (int i = 0; i < n; i++)
    std::cout << i << " " << D[0][i] << std::endl;
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
#define maxn 10010
#define INFTY (1 << 30)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
vector<pair<int, int>> adj[maxn]; // 加权有向图的邻接表表示法

void dijkstra(int s) {
  priority_queue<pair<int, int>> PQ;
  int color[maxn], d[maxn], p[maxn]; // p数组可以不要
  for (int i = 0; i < n; i++) {
    color[i] = WHITE;
    d[i] = INFTY;
    p[i] = -1;
  }
  d[s] = 0;
  PQ.push(make_pair(s, 0));
  color[s] = 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;
        // 优先级队列默认优先最大值，所以要乘以-1
        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, u, v, c;
  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(0);
  return 0;
}


Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;

#define maxn 110
#define INFTY (1 << 30)
#define WHITE 0
#define GRAY 1 // 在本题中，这个可以去掉，无关紧要
#define BLACK 2
int n, m[maxn][maxn];

void dijkstra(int s) // 从s开始求最短路径
{
  int minv, u;
  int d[maxn], p[maxn], color[maxn]; // 在本题中，p数组起不到什么作用，可以去掉
  for (int i = 0; i < n; i++) // 初始化
  {
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }
  d[s] = 0;

  while (1) {
    minv = INFTY;
    u = -1;

    for (int i = 0; i < n; i++) // 寻找最小顶点
    {
      if (color[i] != BLACK && d[i] < minv) // 类似prim算法
      {
        minv = d[i];
        u = i;
      }
    }
    if (u == -1)
      break;
    color[u] = BLACK;

    for (int v = 0; v < n; v++) {
      if (color[v] != BLACK && m[u][v] != INFTY) // 注意这里与prim算法的细微差别
      {
        if (d[u] + m[u][v] < d[v]) {
          d[v] = d[u] + m[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }

  for (int i = 0; i < n; i++)
    cout << i << " " << d[i] << endl;
}

int main() {
  int k, u, v, c;
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      m[i][j] = INFTY;

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

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second

vector<pair<int, int>> adj[10010];
priority_queue<pair<int, int>> pq;
int nodes[10010];

int main() {
  memset(nodes, -1, sizeof(nodes));
  int n, node, k, v, c;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> node >> k;
    for (int j = 0; j < k; ++j) {
      cin >> v >> c;
      adj[node].push_back(make_pair(v, c));
    }
  }
  pq.push(make_pair(0, 0));
  while (!pq.empty()) {
    pair<int, int> cur = pq.top();
    pq.pop();
    if (nodes[cur.se] != -1) { // kalo udh didatengin
      continue;
    } else
      nodes[cur.se] = -cur.fi;
    for (int i = 0; i < adj[cur.se].size(); i++) {
      pq.push(make_pair(-adj[cur.se][i].se + cur.fi, adj[cur.se][i].fi));
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << i << " " << nodes[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <queue>
#include <stdio.h>
#include <string.h>
using namespace std;
#define INF 1 << 30
struct ss {
  int next;
  int to;
  int val;
} e[200050];
int head[200050];
int tot;
void add(int x, int y, int val) {
  e[tot].next = head[x];
  e[tot].to = y;
  e[tot].val = val;
  head[x] = tot++;
}
int n;
int vis[200000];
int dis[200050];
void spfa() {
  for (int i = 0; i < n; i++) {
    dis[i] = INF;
  }
  vis[0] = 1;
  dis[0] = 0;
  queue<int> st;
  st.push(0);
  while (!st.empty()) {
    int t = st.front();
    st.pop();
    vis[t] = 0;
    for (int i = head[t]; i != -1; i = e[i].next) {
      int to = e[i].to;
      if (dis[to] > dis[t] + e[i].val) {
        dis[to] = dis[t] + e[i].val;
        if (!vis[to]) {
          st.push(to);
          vis[to] = 1;
        }
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  tot = 0;
  memset(head, -1, sizeof(head));
  int a, to, val, num;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a, &num);
    for (int j = 1; j <= num; j++) {
      scanf("%d %d", &to, &val);
      add(a, to, val);
    }
  }
  spfa();
  printf("0 0\\n");
  for (int i = 1; i < n; i++) {
    printf("%d %d\\n", i, dis[i]);
  }
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
int maxn = 1 << 30;
int n;
int color[10005];
int d[10005];
vector<pair<int, int>> bian[10005];
int f() {
  priority_queue<pair<int, int>> pq;
  for (int i = 0; i < n; i++) {
    d[i] = maxn;
  }
  d[0] = 0;
  pq.push(make_pair(0, 0));
  while (!pq.empty()) {
    pair<int, int> x = pq.top();
    pq.pop();
    int u = x.second;
    color[u] = 1;
    if (d[u] < x.first * (-1))
      continue;
    for (int i = 0; i < bian[u].size(); i++) {
      int v = bian[u][i].first;
      if (color[v] == 1)
        continue;
      if (d[v] > (d[u] + bian[u][i].second)) {
        d[v] = d[u] + bian[u][i].second;
        pq.push(make_pair(d[v] * (-1), v));
        color[v] = 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", i);
    printf("%d\\n", (d[i] == maxn) ? -1 : d[i]);
  }
}
int main() {
  int k, u, c, g;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &k, &u);
    for (int j = 0; j < u; j++) {
      scanf("%d%d", &c, &g);
      bian[k].push_back(make_pair(c, g));
    }
  }
  f();
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
int n, H[100][100];
void dd() {
  int minv;
  int d[100], c[100];
  for (int i = 0; i < n; i++)
    d[i] = INFTY;
  d[0] = 0;
  while (1) {
    minv = INFTY;
    int u = -1;
    for (int i = 0; i < n; i++) {
      if (minv > d[i] && c[i] != BLACK) {
        u = i;
        minv = d[i];
      }
    }
    if (u == -1)
      break;
    c[u] = BLACK;
    for (int v = 0; v < n; v++) {
      if (c[v] != BLACK && H[u][v] != INFTY) {
        if (d[v] > d[u] + H[u][v]) {
          d[v] = d[u] + H[u][v];
          c[v] = GRAY;
        }
      }
    }
  }
  for (int i = 0; i < n; i++)
    printf("%d %d\\n", i, (d[i] == INFTY ? -1 : d[i]));
}
int main() {
  int a, b, c, d;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      H[i][j] = INFTY;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &a, &b);
    for (int j = 0; j < b; j++) {
      scanf("%d %d", &c, &d);
      H[a][c] = d;
    }
  }
  dd();
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
static const int MAX = 100000;
static const int INFTY = 2000000000;
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]) << "\\n";
}
int main() {
  int k, u, v, c;
  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 = 2000000000;
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]) << "\\n";
}
int main() {
  int k, u, v, c;
  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;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for (int i = 0; i < (int)n; i++)
#define Loop1(i, n) for (int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for (int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

static const int N = 10005;

struct vertex {
  int id;
  int p;
  int d;
  bool operator<(const vertex &another) const {
    return (d != another.d ? d > another.d : id > another.id);
  }
};

struct edge {
  int end;
  int w;
};

int main() {
  int n;
  cin >> n;
  vector<vector<edge>> E(N);
  Loop(i, n) {
    int u, k;
    cin >> u >> k;
    Loop(i, k) {
      int v, c;
      cin >> v >> c;
      E[u].push_back({v, c});
    }
  }
  //
  priority_queue<vertex> pq;
  vi color(N, 0), dist(N, 0);
  pq.push({0, -1, 0});
  while (pq.size() > 0) {
    vertex v = pq.top();
    pq.pop();
    if (color[v.id] == 1)
      continue;
    dist[v.id] = v.d;
    color[v.id] = 1;
    Loop(j, E[v.id].size()) {
      pq.push({E[v.id][j].end, v.id, dist[v.id] + E[v.id][j].w});
    }
  }
  Loop(i, n) { cout << i << " " << dist[i] << endl; }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for (int i = 0; i < (int)n; i++)
#define Loop1(i, n) for (int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for (int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

static const int N = 105;

struct vertex {
  int id;
  int p;
  int d;
  bool operator<(const vertex &another) const {
    return (d != another.d ? d > another.d : id > another.id);
  }
};

struct edge {
  int end;
  int w;
};

int main() {
  int n;
  cin >> n;
  vector<vector<edge>> E(N);
  Loop(i, n) {
    int u, k;
    cin >> u >> k;
    Loop(i, k) {
      int v, c;
      cin >> v >> c;
      E[u].push_back({v, c});
    }
  }
  //
  priority_queue<vertex> pq;
  vi color(N, 0), dist(N, 0);
  pq.push({0, -1, 0});
  while (pq.size() > 0) {
    vertex v = pq.top();
    pq.pop();
    if (color[v.id] == 1)
      continue;
    dist[v.id] = v.d;
    color[v.id] = 1;
    Loop(j, E[v.id].size()) {
      pq.push({E[v.id][j].end, v.id, dist[v.id] + E[v.id][j].w});
    }
  }
  Loop(i, n) { cout << i << " " << dist[i] << endl; }
  return 0;
}