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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int inf = 0x3f3f3f3f;
int map1[109][109];
int flag[109];
int result[109];
int main() {
  int n;
  int u, v, w, k;
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        if (i == j)
          map1[i][j] = 0;
        else
          map1[i][j] = inf;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &u, &k);
      for (int j = 0; j < k; j++) {
        scanf("%d%d", &v, &w);
        if (map1[u][v] > w)
          map1[u][v] = w;
      }
    }
    u = 108;
    memset(flag, 0, sizeof(flag));
    flag[0] = 1;
    for (int i = 0; i < n; i++)
      result[i] = map1[0][i];
    for (int i = 0; i < n; i++) {
      int minn = inf;
      for (int j = 0; j < n; j++)
        if (!flag[j] && result[j] < minn) {
          minn = result[j];
          u = j;
        }
      flag[u] = 1;
      for (int k = 0; k < n; k++)
        if (map1[u][k] != inf && result[k] > result[u] + map1[u][k])
          result[k] = result[u] + map1[u][k];
    }
    for (int i = 0; i < n; i++)
      printf("%d %d\\n", i, result[i]);
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <queue>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 250;
const int MAXM = 1000;
int n, m;
int vis[MAXN];
struct Edge {
  int to, weight, next;
} edge[MAXM];
int head[MAXN];
int cnt;
int d[MAXN];
void addEdge(int from, int to, int weight) {
  edge[cnt].to = to;
  edge[cnt].weight = weight;
  edge[cnt].next = head[from];
  head[from] = cnt++;
}
void SPFA(int start) {
  queue<int> q;
  memset(d, INF, sizeof(d));
  memset(vis, 0, sizeof(vis));
  q.push(start);
  d[start] = 0;
  while (!q.empty()) {
    int from = q.front();
    q.pop();
    vis[from] = 0;
    for (int i = head[from]; i != -1; i = edge[i].next) {
      int to = edge[i].to;
      int weight = edge[i].weight;
      if (d[to] > d[from] + weight) {
        d[to] = d[from] + weight;
        if (!vis[to]) {
          vis[to] = 1;
          q.push(to);
        }
      }
    }
  }
}
int main() {
  int from, to, weight, k;
  while (scanf("%d", &n) != EOF) {
    m = 0;
    memset(head, -1, sizeof(head));
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &from, &k);
      m += k;
      for (int i = 0; i < k; i++) {
        scanf("%d%d", &to, &weight);
        addEdge(from, to, weight);
      }
    }
    SPFA(0);
    for (int i = 0; i < n; i++)
      printf("%d %d\\n", i, d[i]);
  }
  return 0;
}
Problem p02242 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
int n, mp[101][101], D[101];

void dijkstra() {
  bool used[101] = {};
  for (int i = 0; i < 101; i++)
    D[i] = INF;
  D[0] = 0;

  while (1) {
    int cost = INF, pos = -1;
    for (int i = 0; i < n; i++)
      if (!used[i] && D[i] < cost)
        pos = i, cost = D[i];
    if (pos == -1)
      return;
    used[pos] = 1;
    for (int i = 0; i < n; i++)
      D[i] = min(D[i], cost + mp[pos][i]);
  }
}

int main() {

  cin >> n;
  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 101; j++)
      mp[i][j] = INF;

  for (int i = 0, a, m; i < n; i++) {
    cin >> a >> m;
    for (int j = 0, b, c; j < m; j++)
      cin >> b >> c, mp[a][b] = c;
  }
  dijkstra();
  for (int i = 0; i < n; i++)
    cout << i << " " << D[i] << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#define INF 100000000
using namespace std;
int main() {
  int n;
  cin >> n;
  int u, k, v, c;
  int mp[101][101], d[101];
  for (int i = 0; i <= 100; i++) {
    d[i] = INF;
    for (int j = 0; j <= 100; j++)
      mp[i][j] = INF;
  }
  while (u != n - 1) {
    cin >> u >> k;
    for (int i = 0; i < k; i++) {
      cin >> v >> c;
      mp[u][v] = c;
    }
  }

  int mn, s, t[101] = {}, cn = n - 1;
  d[0] = 0, t[0] = 1;
  while (cn) {
    mn = INF;
    for (int i = 0; i < n; i++) {
      if (t[i] == 0) {
        if (d[i] > d[s] + mp[s][i])
          d[i] = d[s] + mp[s][i];
        if (mn > d[i])
          mn = d[i], k = i;
      }
    }
    if (mn != INF)
      cn--, t[k] = 1;
  }
  for (int i = 0; i < n; i++)
    cout << i << " " << d[i] << endl;

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

#include <iostream>
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, 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;
  }

  color[0] = GRAY;
  d[0] = 0;

  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] == INFTY ? -1 : 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();
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
#define INF 100000
using namespace std;
typedef long long ll;
ll q[210][210];
int p[210];
ll dis[210];

void Dijkstra(int N) {
  fill(dis, dis + 210, INF);
  dis[0] = 0;
  while (p[N - 1] == 0) {
    int x = -1;
    ll mini = INF;
    for (int i = 0; i < N; i++) {
      if (p[i] == 1)
        continue;
      if (mini > dis[i]) {
        mini = dis[i];
        x = i;
      }
    }
    p[x] = 1;
    for (int y = 0; y < N; y++) {
      if (p[y] == 1)
        continue;
      dis[y] = min(dis[y], dis[x] + q[x][y]);
    }
  }
}

int main() {
  int u, N, k, v;
  ll C;
  while (~scanf("%d", &N)) {
    fill(q[0], q[0] + 210 * 210, INF);
    fill(p, p + 210, 0);
    int M = N;
    while (N--) {
      scanf("%d%d%", &u, &k);
      for (int i = 0; i < k; i++) {
        scanf("%d%lld", &v, &C);
        q[u][v] = min(q[u][v], C);
        q[v][u] = q[u][v];
      }
    }
    Dijkstra(M);
    for (int i = 0; i < M; i++) {
      printf("%d %lld\\n", i, dis[i]);
    }
  }
  return 0;
}
Problem p02242 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdint>
#include <vector>

using namespace std;

#define GRAPH_SIZE 100
#define WEIGHT_MAX (1 << 21)

enum state_t {
  WHITE,
  GRAY,
  BLACK,
};

static uint32_t graph[GRAPH_SIZE][GRAPH_SIZE];
static state_t state[GRAPH_SIZE];
static uint32_t dist[GRAPH_SIZE];

size_t single_source_shotest_path(size_t num) {
  size_t cost = 0;

  for (uint32_t i = 0; i < num; i++) {
    state[i] = WHITE;
    dist[i] = WEIGHT_MAX;
  }

  state[0] = GRAY;
  dist[0] = 0;

  while (true) {
    size_t minimum_cost = WEIGHT_MAX;
    uint32_t to = 0;
    for (uint32_t i = 0; i < num; i++) {
      if ((dist[i] < minimum_cost) && (state[i] != BLACK)) {
        minimum_cost = dist[i];
        to = i;
      }
    }

    if (minimum_cost == WEIGHT_MAX)
      break;

    cost += minimum_cost;
    state[to] = BLACK;

    for (uint32_t i = 0; i < num; i++) {
      if (((dist[to] + graph[to][i]) < dist[i]) && state[i] != BLACK) {
        state[i] = GRAY;
        dist[i] = dist[to] + graph[to][i];
      }
    }
  }

  return cost;
}

#include <iostream>

int32_t main() {
  uint32_t num;
  cin >> num;

  for (uint32_t i = 0; i < num; i++) {
    for (uint32_t j = 0; j < num; j++) {
      graph[i][j] = WEIGHT_MAX;
    }
  }

  for (uint32_t i = 0; i < num; i++) {
    uint32_t index, len;
    cin >> index >> len;
    for (uint32_t j = 0; j < len; j++) {
      uint32_t v, c;
      cin >> v >> c;
      graph[index][v] = c;
    }
  }

  single_source_shotest_path(num);

  for (uint32_t i = 0; i < num; i++) {
    cout << i << " " << dist[i] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdint>
#include <vector>

using namespace std;

#define GRAPH_SIZE 100

enum state_t {
  WHITE,
  GRAY,
  BLACK,
};

static vector<uint32_t> graph[GRAPH_SIZE];
static state_t state[GRAPH_SIZE];
static uint32_t dist[GRAPH_SIZE];

size_t single_source_shotest_path(size_t num) {
  size_t cost = 0;
  for (uint32_t i = 0; i < num; i++) {
    state[i] = WHITE;
    dist[i] = UINT32_MAX;
  }

  state[0] = GRAY;
  dist[0] = 0;

  while (true) {
    size_t minimum_cost = UINT32_MAX;
    uint32_t to = 0;
    for (uint32_t i = 0; i < num; i++) {
      if (dist[i] < minimum_cost) {
        minimum_cost = dist[i];
        to = i;
      }
    }

    if (minimum_cost == UINT32_MAX)
      break;

    cost += dist[to];

    for (uint32_t i = 0; i < graph[to].size(); i++) {
      if (((dist[to] + graph[to][i]) < dist[graph[to][i]]) &&
          state[i] != BLACK) {
        state[i] = GRAY;
        dist[i] = dist[to] + graph[to][i];
      }
    }
  }

  return cost;
}

#include <iostream>

int32_t main() {
  uint32_t num;
  cin >> num;

  for (uint32_t i = 0; i < num; i++) {
    uint32_t index, len;
    cin >> index >> len;
    for (uint32_t j = 0; j < len; j++) {
      uint32_t val;
      cin >> val;
      graph[i].push_back(val);
    }
  }

  cout << single_source_shotest_path(num) << endl;

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

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

int x[10000][2000];
int x2[10000][2000];
int y[10000];
int z[10000];

int main() {
  memset(x, 1, sizeof(x));
  memset(y, 1, sizeof(y));
  int n, a, b, c, d, e;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    for (int i = 0; i < b; i++) {
      cin >> c >> d;
      x[a][z[a]] = c;
      x2[a][z[a]] = d;
      z[a]++;
    }
  }
  y[0] = 0;
  e = min(n, 1600);
  for (int i = 0; i < e; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < z[j]; k++) {
        y[x[j][k]] = min(y[x[j][k]], y[j] + x2[j][k]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i << ' ' << y[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int x[10000][2000];
int x2[10000][2000];
int y[10000];
int z[10000];

int main() {
  memset(x, 1, sizeof(x));
  memset(y, 1, sizeof(y));
  int n, a, b, c, d, e;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    for (int i = 0; i < b; i++) {
      cin >> c >> d;
      x[a][z[a]] = c;
      x2[a][z[a]] = d;
      z[a]++;
    }
  }
  y[0] = 0;
  e = min(n, 2000);
  for (int i = 0; i < e; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < z[j]; k++) {
        y[x[j][k]] = min(y[x[j][k]], y[j] + x2[j][k]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i << ' ' << y[i] << endl;
  }
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int *c;

struct job {
  int id;
  job(int i) { this->id = i; }
  bool operator<(job j) const { return c[this->id] > c[j.id]; }
};

int main() {
  int n;
  scanf("%d", &n);

  c = new int[n];
  vector<vector<pair<int, int>>> paths;

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

    vector<pair<int, int>> path;
    c[u] = u ? INT_MAX : 0;
    while (k--) {
      int v, c;
      scanf("%d %d", &v, &c);
      path.push_back(make_pair(v, c));
    }
    paths.push_back(path);
  }

  priority_queue<job> q;
  q.push(job(0));
  while (q.size()) {
    int i = q.top().id;
    q.pop();

    for (int j = 0; j < paths[i].size(); j++) {
      int dest = paths[i][j].first;
      int cost = paths[i][j].second;
      if (c[dest] > c[i] + cost) {
        c[dest] = c[i] + cost;
        q.push(job(dest));
      }
    }
  }

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

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

struct node {
  int id;
  int cost;
  node(int i, int c) {
    this->id = i;
    this->cost = c;
  }
  bool operator<(node c) const { return this->cost > c.cost; }
};

int main() {
  int n;
  scanf("%d", &n);

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

    c[u] = u ? INT_MAX : 0;
    for (int j = 0; j < n; j++) {
      w[u][j] = -1;
    }
    while (k--) {
      int v, c;
      scanf("%d %d", &v, &c);
      w[u][v] = c;
    }
  }

  priority_queue<node> q;
  q.push(*new node(0, 0));
  while (q.size()) {
    int i = q.top().id;
    int ca = q.top().cost;
    q.pop();

    for (int j = 0; j < n; j++) {
      if (w[i][j] != -1 && c[j] > w[i][j] + ca) {
        c[j] = w[i][j] + ca;
        q.push(*new node(j, c[j]));
      }
    }
  }

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

#include <algorithm>
#include <iostream>
#include <queue>
#define MAX 10000
#define INF (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;

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

void Dijkstra() {
  priority_queue<pair<int, int>> PQ;
  int next, min_cost;
  int color[n], dist[n];

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

  dist[0] = 0;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;

  while (!PQ.empty()) {
    pair<int, int> next = PQ.top();
    PQ.pop();
    int u = next.second;

    color[u] = BLACK;

    if (dist[u] < next.first * (-1))
      continue;

    for (int i = 0; i < adj_list[u].size(); ++i) {
      int v = adj_list[u][i].first;
      if (color[v] == BLACK)
        continue;
      if (dist[v] > dist[u] + adj_list[u][i].second) {
        color[v] = GRAY;
        dist[v] = dist[u] + adj_list[u][i].second;
        PQ.push(make_pair(dist[v] * (-1), v));
      }
    }
  }

  int sum = 0;
  for (int i = 0; i < n; ++i) {
    cout << i << ' ' << (dist[i] != INF ? dist[i] : -1) << endl;
  }
}

int main() {
  int id, deg, v, w;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> id >> deg;
    for (int j = 0; j < deg; ++j) {
      cin >> v >> w;
      adj_list[id].push_back(make_pair(v, w));
    }
  }

  Dijkstra();

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#define MAX 1000
#define INF (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;

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

void Dijkstra() {
  priority_queue<pair<int, int>> PQ;
  int next, min_cost;
  int color[n], dist[n];

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

  dist[0] = 0;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;

  while (!PQ.empty()) {
    pair<int, int> next = PQ.top();
    PQ.pop();
    int u = next.second;

    color[u] = BLACK;

    if (dist[u] < next.first * (-1))
      continue;

    for (int i = 0; i < adj_list[u].size(); ++i) {
      int v = adj_list[u][i].first;
      if (color[v] == BLACK)
        continue;
      if (dist[v] > dist[u] + adj_list[u][i].second) {
        color[v] = GRAY;
        dist[v] = dist[u] + adj_list[u][i].second;
        PQ.push(make_pair(dist[v] * (-1), v));
      }
    }
  }

  int sum = 0;
  for (int i = 0; i < n; ++i) {
    cout << i << ' ' << (dist[i] != INF ? dist[i] : -1) << endl;
  }
}

int main() {
  int id, deg, v, w;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> id >> deg;
    for (int j = 0; j < deg; ++j) {
      cin >> v >> w;
      adj_list[id].push_back(make_pair(v, w));
    }
  }

  Dijkstra();

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

#define MAX_V 10000
#define INF INT_MAX / 2

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

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

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

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int n;
  cin >> n;
  V = n;
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      edge e;
      cin >> e.to >> e.cost;
      G[u].push_back(e);
    }
  }
  dijkstra(0);
  for (int i = 0; i < n; i++)
    cout << i << " " << d[i] << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

#define MAX_N 100
#define INF 100000 * 100 + 1

int cost[MAX_N][MAX_N];
int d[MAX_N];
bool used[MAX_N];
int V;

void dijkstra(int s) {
  fill_n(d, V, INF);
  fill_n(used, V, false);
  d[s] = 0;

  while (1) {
    int v = -1;
    for (int u = 0; u < V; u++)
      if (!used[u] && (v == -1 || d[u] < d[v]))
        v = u;

    if (v == -1)
      break;

    used[v] = true;

    for (int u = 0; u < V; u++)
      d[u] = min(d[u], d[v] + cost[v][u]);
  }
}

int main() {
  int n;
  cin >> n;
  V = n;
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    fill_n(cost[u], n, INF);
    for (int j = 0; j < k; j++) {
      int v, c;
      cin >> v >> c;
      cost[u][v] = c;
    }
  }
  dijkstra(0);
  for (int i = 0; i < n; i++) {
    cout << i << " " << d[i] << endl;
  }

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

#include <bits/stdc++.h>
#define d first
#define wgt first
#define to second

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vec;
typedef vector<vec> Graph;

Graph G(11000);
int n, d[11000];

void Dijkstra() {
  bool used[11000];
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  fill(d, d + n, INT_MAX);
  memset(used, false, sizeof(used));
  pq.push(make_pair(0, 0));
  while (!pq.empty()) {
    pii u = pq.top();
    pq.pop();
    if (used[u.to])
      continue;
    used[u.to] = true;
    d[u.to] = u.d;
    for (int i = 0; i < G[u.to].size(); i++)
      if (d[G[u.to][i].to] > d[u.to] + G[u.to][i].wgt) {
        d[G[u.to][i].to] = d[u.to] + G[u.to][i].wgt;
        pq.push(make_pair(d[G[u.to][i].to], G[u.to][i].to));
      }
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int u, t;
    scanf("%d%d", &u, &t);
    for (int j = 0; j < t; j++) {
      int v, w;
      scanf("%d%d", &v, &w);
      G[u].push_back(make_pair(w, v));
    }
  }
  Dijkstra();
  for (int i = 0; i < n; i++)
    printf("%d %d\\n", i, d[i]);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define d first
#define wgt first
#define to second

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vec;
typedef vector<vec> Graph;

Graph G(11000);
int n, d[11000];

void Dijkstra() {
  bool used[1100];
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  fill(d, d + n, INT_MAX);
  memset(used, false, sizeof(used));
  pq.push(make_pair(0, 0));
  while (!pq.empty()) {
    pii u = pq.top();
    pq.pop();
    if (used[u.to])
      continue;
    used[u.to] = true;
    d[u.to] = u.d;
    for (int i = 0; i < G[u.to].size(); i++)
      if (d[G[u.to][i].to] > d[u.to] + G[u.to][i].wgt) {
        d[G[u.to][i].to] = d[u.to] + G[u.to][i].wgt;
        pq.push(make_pair(d[G[u.to][i].to], G[u.to][i].to));
      }
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int u, t;
    scanf("%d%d", &u, &t);
    for (int j = 0; j < t; j++) {
      int v, w;
      scanf("%d%d", &v, &w);
      G[u].push_back(make_pair(w, v));
    }
  }
  Dijkstra();
  for (int i = 0; i < n; i++)
    printf("%d %d\\n", i, d[i]);
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
static const int NMAX = 10000;
#define INF (1 << 30)

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> adj[NMAX];

  for (int i = 0; i < n; i++) {
    int id, nn;
    cin >> id >> nn;
    for (int j = 0; j < nn; j++) {
      int to, weight;
      cin >> to >> weight;
      // use negative weights for priority_queue
      adj[id].push_back(make_pair(-weight, to));
    }
  }

  bool visited[n];
  int dist[n];
  for (int i = 0; i < n; i++) {
    visited[i] = false;
    dist[i] = -INF;
  }

  priority_queue<pair<int, int>> distQ;

  // add node 0
  for (int i = 0; i < adj[0].size(); i++) {
    distQ.push(adj[0][i]);
    int weight = adj[0][i].first;
    int id = adj[0][i].second;
    dist[id] = weight;
  }
  visited[0] = true;

  while (!distQ.empty()) {
    // find nearest node
    int minnode = distQ.top().second;
    distQ.pop();

    // add node
    visited[minnode] = true;

    // update dist
    for (int i = 0; i < adj[minnode].size(); i++) {
      int weight = adj[minnode][i].first;
      int id = adj[minnode][i].second;

      if (visited[id] == false) {
        int newWeight = dist[minnode] + weight;
        if (-newWeight < -dist[id]) {
          distQ.push(make_pair(newWeight, id));
          dist[id] = newWeight;
        }
      }
    }
  }

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

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
static const int NMAX = 100;
#define INF (1 << 30)

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> adj[NMAX];

  for (int i = 0; i < n; i++) {
    int id, nn;
    cin >> id >> nn;
    for (int j = 0; j < nn; j++) {
      int to, weight;
      cin >> to >> weight;
      // use negative weights for priority_queue
      adj[id].push_back(make_pair(-weight, to));
    }
  }

  bool visited[n];
  int dist[n];
  for (int i = 0; i < n; i++) {
    visited[i] = false;
    dist[i] = -INF;
  }

  priority_queue<pair<int, int>> distQ;

  // add node 0
  for (int i = 0; i < adj[0].size(); i++) {
    distQ.push(adj[0][i]);
    int weight = adj[0][i].first;
    int id = adj[0][i].second;
    dist[id] = weight;
  }
  visited[0] = true;

  while (!distQ.empty()) {
    // find nearest node
    int minnode = distQ.top().second;
    distQ.pop();

    // add node
    visited[minnode] = true;

    // update dist
    for (int i = 0; i < adj[minnode].size(); i++) {
      int weight = adj[minnode][i].first;
      int id = adj[minnode][i].second;

      if (visited[id] == false) {
        int newWeight = dist[minnode] + weight;
        if (-newWeight < -dist[id]) {
          distQ.push(make_pair(newWeight, id));
          dist[id] = newWeight;
        }
      }
    }
  }

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