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

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

using namespace std;

typedef pair<int, int> PII;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < n; ++i)
#define mp make_pair

struct edge {
  unsigned short to;
  int cost;
  edge(unsigned short to, int cost) : to(to), cost(cost) {}
};

int V;
vector<edge> G[10000];
int d[10000];
bool used[10000];

void dijkstra(int s) {
  priority_queue<PII, vector<PII>, greater<PII>> Q;
  fill(d, d + V, INF);
  d[s] = 0;
  Q.push(mp(0, s));

  while (!Q.empty()) {
    PII p = Q.top();
    Q.pop();
    int v = p.second;
    used[v] = true;
    if (d[v] < p.first)
      continue;
    rep(i, G[v].size()) {
      edge e = G[v][i];
      if (!used[e.to] && d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        Q.push(mp(d[e.to], e.to));
      }
    }
  }
}
int n;
int main() {
  cin >> V;
  rep(j, V) {
    int u, k;
    cin >> u >> k;
    rep(t, k) {
      int v, c;
      cin >> v >> c;
      G[u].push_back(edge(v, c));
    }
  }
  dijkstra(0);
  rep(i, V) { cout << i << " " << d[i] << endl; }
  return 0;
}

Error: MLE

Fixed submission:

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

using namespace std;

typedef pair<int, int> PII;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < n; ++i)
#define mp make_pair

struct edge {
  unsigned short to;
  int cost;
  edge(unsigned short to, int cost) : to(to), cost(cost) {}
};

int V;
vector<edge> G[10000];
int d[10000];

void dijkstra(int s) {
  priority_queue<PII, vector<PII>, greater<PII>> Q;
  fill(d, d + V, INF);
  d[s] = 0;
  Q.push(mp(0, s));

  while (!Q.empty()) {
    PII p = Q.top();
    Q.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    rep(i, G[v].size()) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        Q.push(mp(d[e.to], e.to));
      }
    }
  }
}
int n;
int main() {
  cin >> V;
  rep(i, V) {
    rep(j, V) {
      int u, k;
      cin >> u >> k;
      rep(t, k) {
        int v, c;
        cin >> v >> c;
        G[u].push_back(edge(v, c));
      }
    }
  }
  dijkstra(0);
  rep(i, V) { cout << i << " " << d[i] << endl; }
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const int INF = 1 << 30;
const int NIL = -1;
const int MAXN = 10005;
int vis[MAXN];
int d[MAXN];
int head[500005];
int n;
int cnt;
struct Edge {
  int to, next, w;
  Edge() {}
} edge[500005];

void add(int u, int v, int w) {
  edge[cnt].to = v;
  edge[cnt].w = w;
  edge[cnt].next = head[u];
  head[u] = cnt++;
}

struct Node {
  int u, w;
  Node(int _u, int _w) : u(_u), w(_w) {}
  friend bool operator<(const Node &a, const Node &b) { return a.w > b.w; }
};

void dijkstra(int s) {
  priority_queue<Node> q;
  for (int i = 0; i < n; ++i)
    d[i] = INF, vis[i] = false;
  d[s] = 0;

  Node t(s, 0);
  q.push(t);
  int u, v, w;
  int count = 0;
  while (!q.empty() && count < n - 1) {
    t = q.top();
    q.pop();
    u = t.u;
    if (d[u] < t.w)
      continue;
    vis[u] = true;
    ++count;
    for (int i = head[u]; i != NIL; i = edge[i].next) {
      v = edge[i].to;
      w = edge[i].w;
      if (!vis[v] && d[v] > d[u] + w) {
        d[v] = d[u] + w;
        q.push(Node(v, d[v]));
      }
    }
  }
  if (count == n - 1)
    for (int i = 0; i < n; ++i)
      printf("%d %d\\n", i, d[i]);
}

int main(void) {
  int k, s, e, w;
  scanf("%d", &n);
  memset(head, NIL, sizeof(-1));
  cnt = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &s, &k);
    while (k--) {
      scanf("%d %d", &e, &w);
      add(s, e, w);
    }
  }
  dijkstra(0);

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const int INF = 1 << 30;
const int NIL = -1;
const int MAXN = 10005;
int graph[MAXN][MAXN];
int vis[MAXN];
int d[MAXN];
int n;
void dijkstra(int s) {
  for (int i = 0; i < n; ++i) {
    vis[i] = false;
    d[i] = graph[0][i];
  }
  vis[s] = true;
  d[s] = 0;
  while (true) {
    int minicost = INF;
    int id = -1;
    for (int i = 0; i < n; ++i) {
      if (!vis[i] && minicost > d[i]) {
        minicost = d[i];
        id = i;
      }
    }
    if (minicost == INF)
      break;
    vis[id] = true;
    for (int i = 0; i < n; ++i) {
      if (!vis[i] && d[i] > d[id] + graph[id][i])
        d[i] = d[id] + graph[id][i];
    }
  }
}

int main(void) {

  int k, s, e, w;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      graph[i][j] = INF;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &s, &k);
    while (k--) {
      scanf("%d %d", &e, &w);
      graph[s][e] = w;
    }
  }
  dijkstra(0);
  for (int i = 0; i < n; ++i)
    printf("%d %d\\n", i, d[i]);

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

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

const int MAX = 10000;
const int INFINITY = 2 << 21;
int n;
vector<pair<int, int>> G[MAX];
int distances[MAX];
int states[MAX];

void dijkstra() {
  int id = 0;
  distances[id] = 0;
  priority_queue<pair<int, int>> PQ;
  PQ.push(make_pair(0, 0));

  while (!PQ.empty()) {
    pair<int, int> p = PQ.top();
    PQ.pop();
    id = p.second;
    states[id] = 1;

    if (distances[id] < p.first * -1)
      continue;

    int s = G[id].size();
    for (int i = 0; i < s; i++) {
      int k = G[id][i].first;
      int v = G[id][i].second;
      if (states[k] == 1)
        continue;
      if (distances[id] + v < distances[k]) {
        distances[k] = distances[id] + v;
        PQ.push(make_pair(distances[k] * -1, k));
      }
    }
  }

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;

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

  dijkstra();

  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;

const int MAX = 10000;
const int INFINITY = 2 << 21;
int n;
int G[MAX][MAX];
int distances[MAX];
int states[MAX];

void dijkstra() {
  int id = 0;
  distances[id] = 0;

  while (1) {
    int min = INFINITY;

    for (int i = 0; i < n; i++) {
      if (states[i] == 0 && distances[i] < min) {
        min = distances[i];
        id = i;
      }
    }

    if (min == INFINITY)
      break;

    for (int i = 0; i < n; i++) {
      if (states[i] != 0 || G[id][i] == -1)
        continue;
      if (distances[id] + G[id][i] < distances[i]) {
        distances[i] = distances[id] + G[id][i];
      }
    }

    states[id] = 1;
  }

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      G[i][j] = INFINITY;
  }

  int u, k, v, c;
  for (int i = 0; i < n; i++) {
    distances[i] = INFINITY;
    states[i] = 0;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      G[i][v] = c;
    }
  }

  dijkstra();

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
  int n;
  cin >> n;
  int ans[10001] = {};
  vector<vector<pair<int, int>>> graph(n + 1);
  for (int i = 0; i < n; i++) {
    ans[i] = -1;
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int v, c;
      cin >> v >> c;
      graph[u].push_back(make_pair(v, c));
    }
  }
  priority_queue<pair<int, int>> qu;
  qu.push(make_pair(0, 0));
  ans[0] = 0;
  while (!qu.empty()) {
    int nowd = -(qu.top()).first;
    int nownode = (qu.top()).second;
    qu.pop();
    for (int i = 0; i < graph[nownode].size(); i++) {
      int node = graph[nownode][i].first;
      int next = nowd + graph[nownode][i].second;
      if (ans[node] < 0 || ans[node] > next) {
        ans[node] = next;
        qu.push(make_pair(-next, node));
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i << " " << ans[i] << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
  int n;
  cin >> n;
  int ans[101] = {};
  vector<vector<pair<int, int>>> graph(n + 1);
  for (int i = 0; i < n; i++) {
    ans[i] = -1;
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int v, c;
      cin >> v >> c;
      graph[u].push_back(make_pair(v, c));
    }
  }
  priority_queue<pair<int, int>> qu;
  qu.push(make_pair(0, 0));
  ans[0] = 0;
  while (!qu.empty()) {
    int nowd = -(qu.top()).first;
    int nownode = (qu.top()).second;
    qu.pop();
    for (int i = 0; i < graph[nownode].size(); i++) {
      int node = graph[nownode][i].first;
      int next = nowd + graph[nownode][i].second;
      if (ans[node] < 0 || ans[node] > next) {
        ans[node] = next;
        qu.push(make_pair(-next, node));
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i << " " << ans[i] << endl;
  }
}
Problem p02243 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
// #include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1 << 20);
int d[MAX], color[MAX];
int n;
vector<pair<int, int>> adj[MAX];

void dijkstra() {
  priority_queue<pair<int, int>> PQ;
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
    color[i] = 0;
  }
  d[0] = 0;
  PQ.push(make_pair(0, 0));
  color[0] = 1;
  while (!PQ.empty()) {
    pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.second;
    // cout<<u<<" "<<color[u]<<endl;
    color[u] = 2;

    // 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] == 2) continue;
      if (color[v] != 2 && 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] = 1;
      }
    }
  }

  return;
}

int main() {
  // freopen("in3.txt","r",stdin);
  int u, k, 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();
  for (int i = 0; i < n; i++) {
    cout << i << " " << d[i] << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
static const int INFTY = (1 << 21);
int n, M[10000][10000];
int color[10000], d[10000], p[10000];

void dijkstra() {
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
    p[i] = -1;
    color[i] = 0;
  }

  d[0] = 0;

  while (true) {
    int mincost = INFTY;
    int u = -1;
    for (int i = 0; i < n; i++) {
      if (color[i] != 2 && d[i] < mincost) {
        mincost = d[i];
        u = i;
      }
    }
    if (mincost == INFTY)
      break;
    color[u] = 2;
    for (int v = 0; v < n; v++) {
      if (color[v] != 2 && d[u] + M[u][v] < d[v]) {
        d[v] = d[u] + M[u][v];
        p[v] = u;
        color[v] = 1;
      }
    }
  }
}

int main() {
  // freopen("in3.txt","r",stdin);
  int u, k, 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();

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

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

#include <stdio.h>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;

typedef long long ll;

int main(void) {
  int n, now = 0;
  scanf("%d", &n);
  ll dis[n];
  rep(i, n) dis[i] = 10e13;
  dis[0] = 0;
  char f[n];
  rep(i, n) f[i] = 0;
  f[0] = 1;
  vector<pair<int, int>> vec[n];
  rep(i, n) {
    int u, k;
    scanf("%d%d", &u, &k);
    rep(j, k) {
      int c, v;
      scanf("%d%d", &v, &c);
      pair<int, int> p = make_pair(v, c);
      vec[u].push_back(p);
    }
  }
  /*rep(i, n) {
    vector< pair<int, int> >::iterator it;
    for(it = vec[i].begin(); it != vec[i].end(); ++it) printf("%d:%d ",
  (*it).first, (*it).second); printf("\\n");
  }*/
  rep(i, n - 1) {
    int j = now;
    vector<pair<int, int>>::iterator it;
    for (it = vec[j].begin(); it != vec[j].end(); ++it) {
      if (dis[(*it).first] > dis[j] + (*it).second)
        dis[(*it).first] = dis[j] + (*it).second;
    }
    ll min = 10e13, minn;
    rep(k, n) if (!f[k] && min > dis[k]) min = dis[k], minn = k;
    f[minn] = 1;
    now = minn;
    /*rep(j, n) printf("%d ", dis[j]);
    printf("\\n");*/
  }
  rep(i, n) printf("%d %lld\\n", i, dis[i]);
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;

typedef long long ll;

int main(void) {
  int n;
  scanf("%d", &n);
  ll dis[n];
  rep(i, n) dis[i] = 10e13;
  dis[0] = 0;
  vector<pair<int, int>> vec[n];
  rep(i, n) {
    int u, k;
    scanf("%d%d", &u, &k);
    rep(j, k) {
      int c, v;
      scanf("%d%d", &v, &c);
      pair<int, int> p = make_pair(v, c);
      vec[u].push_back(p);
    }
  }
  /*rep(i, n) {
    vector< pair<int, int> >::iterator it;
    for(it = vec[i].begin(); it != vec[i].end(); ++it) printf("%d:%d ",
  (*it).first, (*it).second); printf("\\n");
  }*/
  rep(i, n - 1) {
    rep(j, n) {
      vector<pair<int, int>>::iterator it;
      for (it = vec[j].begin(); it != vec[j].end(); ++it) {
        if (dis[(*it).first] > dis[j] + (*it).second)
          dis[(*it).first] = dis[j] + (*it).second;
      }
    }
    /*rep(j, n) printf("%d ", dis[j]);
    printf("\\n");*/
  }
  rep(i, n) printf("%d %lld\\n", i, dis[i]);
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#define INF 1000000000
using namespace std;

struct edge {
  int to, cost;
};
typedef pair<int, int> P;

int main() {
  int n;
  vector<edge> es[10000];
  priority_queue<P, vector<P>, greater<P>> que;
  int d[10000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    int now, m;
    cin >> now >> m;
    for (int j = 0; j < m; j++) {
      int a, b;
      cin >> a >> b;
      es[now].push_back({a, b});
    }
    d[i] = INF;
  }
  d[0] = 0;
  que.push(make_pair(0, 0));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < es[v].size(); i++) {
      edge e = es[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(make_pair(d[e.to], e.to));
      }
    }
  }
  for (int i = 0; i < n; i++)
    cout << i << " " << d[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#define INF 1000000000
using namespace std;

struct edge {
  int to, cost;
};
typedef pair<int, int> P;

int main() {
  int n;
  vector<edge> es[100];
  priority_queue<P, vector<P>, greater<P>> que;
  int d[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    int now, m;
    cin >> now >> m;
    for (int j = 0; j < m; j++) {
      int a, b;
      cin >> a >> b;
      es[now].push_back({a, b});
    }
    d[i] = INF;
  }
  d[0] = 0;
  que.push(make_pair(0, 0));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < es[v].size(); i++) {
      edge e = es[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(make_pair(d[e.to], e.to));
      }
    }
  }
  for (int i = 0; i < n; i++)
    cout << i << " " << d[i] << endl;
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
#define MAX 10000
#define INF (1 << 30)

using namespace std;
enum state { BLACK, WHITE };

int main() {
  vector<pair<int, int>> a[MAX];
  int n;
  cin >> n;
  int d[MAX];
  state s[MAX];

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

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

  priority_queue<pair<int, int>> q;
  q.push(make_pair(0, 0));

  while (!q.empty()) {
    pair<int, int> p;
    p = q.top();
    q.pop();
    if (s[p.second] == BLACK)
      continue;
    d[p.second] = p.first * -1;
    s[p.second] = BLACK;

    for (auto it = a[p.second].begin(); it != a[p.second].end(); it++) {
      int i = it->first;
      int cost = it->second;
      if (s[i] == WHITE && d[i] > d[p.second] + cost) {
        d[i] = d[p.second] + cost;
        q.push(make_pair(d[i] * -1, i));
      }
    }
  }

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

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
#define MAX 10000
#define INF (1 << 30)

using namespace std;
enum state { BLACK, WHITE };

int main() {
  vector<int> v[MAX];
  vector<int> c[MAX];
  state s[MAX];
  int d[MAX];
  int n;
  cin >> n;

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

  for (int i = 0; i < n; i++) {
    s[i] = WHITE;
    d[i] = INF;
  }
  s[0] = BLACK;
  d[0] = 0;

  vector<int> blacklist;
  blacklist.push_back(0);

  while (1) {
    int &last = blacklist.back();
    for (int i = 0; i < v[last].size(); i++) {
      if (d[v[last][i]] > d[last] + c[last][i]) {
        d[v[last][i]] = d[last] + c[last][i];
      }
    }

    int minv = -1;
    int mind = INF;
    for (int b : blacklist) {
      for (int i = 0; i < v[b].size(); i++) {
        if (s[v[b][i]] != BLACK && d[v[b][i]] < mind) {
          minv = v[b][i];
          mind = d[v[b][i]];
        }
      }
    }
    if (minv != -1) {
      s[minv] = BLACK;
      blacklist.push_back(minv);
    } else {
      break;
    }
  }

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

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

const int MAX_N = 10000;
const int INF = (1 << 21);

int N;
vector<pair<int, int>> A[MAX_N];

void dj() {
  int d[MAX_N], c[MAX_N];

  // (first: distance*-1, second: adjacent)
  priority_queue<pair<int, int>> PQ;

  for (int i = 0; i < N; i++) {
    d[i] = INF;
    c[i] = -1;
  }

  d[0] = c[0] = 0;
  PQ.push(make_pair(0, 0));

  while (!PQ.empty()) {
    pair<int, int> t = PQ.top();
    PQ.pop();
    int cur_n = t.second;
    c[cur_n] = 1;

    if (d[cur_n] < t.first * -1)
      continue;

    for (int i = 0; i < A[cur_n].size(); i++) {
      int adj_n = A[cur_n][i].first;

      if (c[adj_n] == 1)
        continue;

      if (d[cur_n] + A[cur_n][i].second < d[adj_n]) {
        d[adj_n] = d[cur_n] + A[cur_n][i].second;
        PQ.push(make_pair(d[adj_n] * -1, adj_n));
        c[adj_n] = 0;
      }
    }
  }

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

int main() {
  cin >> N;

  for (int i = 0; i < N; i++) {
    int cur_n, k;
    cin >> cur_n >> k;

    for (int j = 0; j < k; j++) {
      int u, v;
      cin >> u >> v;
      A[cur_n].push_back(make_pair(u, v));
    }
  }

  dj();

  return 0;
}

Error: 0

Fixed submission:

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

const int MAX_N = 100;
const int INF = (1 << 21);

int N;
vector<pair<int, int>> A[MAX_N];

void dj() {
  int d[MAX_N], c[MAX_N];

  // (first: distance*-1, second: adjacent)
  priority_queue<pair<int, int>> PQ;

  for (int i = 0; i < N; i++) {
    d[i] = INF;
    c[i] = -1;
  }

  d[0] = c[0] = 0;
  PQ.push(make_pair(0, 0));

  while (!PQ.empty()) {
    pair<int, int> t = PQ.top();
    PQ.pop();
    int cur_n = t.second;
    c[cur_n] = 1;

    if (d[cur_n] < t.first * -1)
      continue;

    for (int i = 0; i < A[cur_n].size(); i++) {
      int adj_n = A[cur_n][i].first;

      if (c[adj_n] == 1)
        continue;

      if (d[cur_n] + A[cur_n][i].second < d[adj_n]) {
        d[adj_n] = d[cur_n] + A[cur_n][i].second;
        PQ.push(make_pair(d[adj_n] * -1, adj_n));
        c[adj_n] = 0;
      }
    }
  }

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

int main() {
  cin >> N;

  for (int i = 0; i < N; i++) {
    int cur_n, k;
    cin >> cur_n >> k;

    for (int j = 0; j < k; j++) {
      int u, v;
      cin >> u >> v;
      A[cur_n].push_back(make_pair(u, v));
    }
  }

  dj();

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

#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define M 10010
long long int Min(long long int x, long long int y) { return x > y ? x : y; }
int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> adjancent[M];
  for (int i = 0; i < N; i++) {
    int node, degree, to, cost;
    cin >> node >> degree;
    for (int l = 0; l < degree; l++) {
      cin >> to >> cost;
      adjancent[node].push_back(make_pair(to, cost));
    }
  }
  priority_queue<pair<long long int, long long int>> descending;
  descending.push(make_pair(0, 0));
  vector<long long int> dp(N, 2400000000);
  dp[0] = 0;
  while (descending.size() != 0) {
    pair<long long int, long long int> now = descending.top();
    descending.pop();
    for (int i = 0; i < adjancent[now.first].size(); i++) {
      pair<long long int, long long int> next = adjancent[now.first][i];
      if (dp[next.first] > dp[now.first] + next.second) {
        dp[next.first] = dp[now.first] + next.second;
        descending.push(make_pair(next.first, dp[next.first]));
      }
    }
  }
  for (int i = 0; i < N; i++)
    cout << i << " " << dp[i] << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define M 100
int Min(int x, int y) { return x > y ? x : y; }
int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> adjancent[M];
  for (int i = 0; i < N; i++) {
    int node, degree, to, cost;
    cin >> node >> degree;
    for (int l = 0; l < degree; l++) {
      cin >> to >> cost;
      adjancent[node].push_back(make_pair(to, cost));
    }
  }
  priority_queue<pair<int, int>> descending;
  descending.push(make_pair(0, 0));
  vector<long long int> dp(N, 2400000000);
  dp[0] = 0;
  while (descending.size() != 0) {
    pair<int, int> now = descending.top();
    descending.pop();
    for (int i = 0; i < adjancent[now.first].size(); i++) {
      pair<int, int> next = adjancent[now.first][i];
      if (dp[next.first] > dp[now.first] + next.second) {
        dp[next.first] = dp[now.first] + next.second;
        descending.push(make_pair(next.first, dp[next.first]));
      }
    }
  }
  for (int i = 0; i < N; i++)
    cout << i << " " << dp[i] << endl;
  return 0;
}