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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> pii;

int main() {
  int n;
  scanf("%d", &n);
  vector<vector<pii>> G(n);
  for (int i = 0; i < n; ++i) {
    int u, k, v, c;
    scanf("%d%d", &u, &k);
    for (int j = 0; j < k; ++j) {
      scanf("%d%d", &v, &c);
      G[u].push_back(pii(c, v));
    }
  }

  vector<int> d(n, 1 << 30);
  d[0] = 0;
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  pq.push(pii(0, 0));
  while (!pq.empty()) {
    int c = pq.top().first;
    int u = pq.top().second;
    pq.pop();
    if (d[u] != c) {
      continue;
    }
    for (int i = 0; i < G[u].size(); ++i) {
      int b = c + G[u][i].first;
      int v = G[u][i].second;
      if (d[v] > b) {
        d[v] = b;
        pq.push(pii(b, v));
      }
    }
  }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

typedef pair<int, int> pii;

int main() {
  int n;
  scanf("%d", &n);
  vector<vector<pii>> G(n);
  for (int i = 0; i < n; ++i) {
    int u, k, v, c;
    scanf("%d%d", &u, &k);
    for (int j = 0; j < k; ++j) {
      scanf("%d%d", &v, &c);
      G[u].push_back(pii(c, v));
    }
  }

  vector<int> d(n, 1 << 30);
  d[0] = 0;
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  pq.push(pii(0, 0));
  while (!pq.empty()) {
    int c = pq.top().first;
    int u = pq.top().second;
    if (d[u] != c) {
      continue;
    }
    for (int i = 0; i < G[u].size(); ++i) {
      int b = c + G[u][i].first;
      int v = G[u][i].second;
      if (d[v] > b) {
        d[v] = b;
        pq.push(pii(b, v));
      }
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
static const int INF = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int NIL = -1;
static const int MAX = 10000;

int n;
vector<vector<pair<int, int>>> M(MAX);

void dijstra(int s) {
  vector<int> color(n, WHITE);
  vector<int> d(n, INF);
  d[s] = 0;
  priority_queue<pair<int, int>> pq;
  pq.push(make_pair(0, 0));

  while (!pq.empty()) {
    pair<int, int> tmp = pq.top();
    pq.pop();

    int u = tmp.second;
    color[u] = BLACK;
    if (d[u] < tmp.first * (-1))
      continue;

    int size = M[u].size();
    for (int i = 0; i < size; i++) {
      int v = M[u][i].second;
      if (color[v] == BLACK)
        continue;

      if (d[u] + M[u][i].first < d[v]) {
        d[v] = d[u] + M[u][i].first;
        color[v] = GRAY;
        pq.push(make_pair(d[v] * (-1), v));
      }
    }
  }
  int res = 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 id, k;
    cin >> id >> k;
    for (int j = 0; j < k * 2; j += 2) {
      pair<int, int> p;
      cin >> p.second >> p.first;
      M[id].push_back(p);
    }
  }
  dijstra(0);
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
static const int INF = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int NIL = -1;
static const int MAX = 100;

int n;
vector<vector<int>> M(MAX, vector<int>(MAX, NIL));

void dijstra(int s) {
  vector<int> color(n, WHITE);
  vector<int> d(n, INF);
  vector<int> p(n);
  d[s] = 0;
  p[s] = NIL;

  while (true) {
    int u = 0;
    int mincost = INF;
    for (int i = 0; i < n; i++) {
      if (color[i] != BLACK && d[i] < mincost) {
        mincost = d[i];
        u = i;
      }
    }
    if (mincost == INF) {
      break;
    }

    color[u] = BLACK;

    for (int v = 0; v < n; v++) {
      if (color[v] != BLACK && M[u][v] != NIL) {
        if (d[u] + M[u][v] < d[v]) {
          d[v] = d[u] + M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
  int res = 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 id, k;
    cin >> id >> k;
    for (int j = 0; j < k * 2; j += 2) {
      int v, c;
      cin >> v >> c;
      M[id][v] = c;
    }
  }
  dijstra(0);
}
Problem p02243 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
struct Edge {
  int d, i, j;
  Edge(int d_, int i_, int j_) : d(d_), i(i_), j(j_) {}
  bool operator<(const Edge &right) const { return d > right.d; }
};
void calc(int t, vector<vector<pair<int, int>>> &G, vector<int> &distance) {
  int new_black = t;
  priority_queue<Edge> temp;
  for (int i = 1; i < G.size(); i++) {
    for (int j = 0; j < G[new_black].size(); j++) {
      if (distance[G[new_black][j].first] != -1)
        continue;
      int dis = G[new_black][j].second + distance[new_black];
      temp.push(Edge(dis, new_black, G[new_black][j].first));
    }
    while (distance[temp.top().j] != -1)
      temp.pop();
    distance[temp.top().j] = temp.top().d;
    new_black = temp.top().j;
    temp.pop();
  }
}

int main() {
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> G(n);
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    G[u].resize(k);
    for (int j = 0; j < k; j++) {
      int v, c;
      cin >> v >> c;
      G[u][j] = make_pair(v, c);
    }
  }

  vector<int> distance(n, -1);
  distance[0] = 0;
  calc(0, G, distance);
  for (int i = 0; i < n; i++) {
    cout << i << " " << distance[i] << endl;
  }
  return 0;
}


Error: MLE

Fixed submission:

#include <iostream>
#include <queue>
#include <vector>
using namespace std;
struct Edge {
  int d, i, j;
  Edge(int d_, int i_, int j_) : d(d_), i(i_), j(j_) {}
  bool operator<(const Edge &right) const { return d > right.d; }
};
void calc(int t, vector<vector<int>> &G, vector<int> &distance) {
  int new_black = t;
  priority_queue<Edge> temp;
  for (int i = 1; i < G.size(); i++) {
    for (int j = 0; j < G.size(); j++) {
      if (distance[j] != -1)
        continue;
      int dis = G[new_black][j] + distance[new_black];
      temp.push(Edge(dis, new_black, j));
    }
    while (distance[temp.top().j] != -1)
      temp.pop();
    distance[temp.top().j] = temp.top().d;
    new_black = temp.top().j;
    temp.pop();
  }
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> G(n, vector<int>(n, 1e8));
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int c, v;
      cin >> c >> v;
      G[u][c] = v;
    }
  }

  vector<int> distance(n, -1);
  distance[0] = 0;
  calc(0, G, distance);
  for (int i = 0; i < n; i++) {
    cout << i << " " << distance[i] << endl;
  }
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

typedef pair<int, int> pii;
#define INF 0x3f3f3f3f
#define fi first
#define se second

int mcos[10005];
vector<pii> G[1000005];
int N;

void dijkstra(int start) {
  priority_queue<pii, vector<pii>, greater<pii>> pq;

  pq.push(pii(0, start));
  memset(mcos, INF, sizeof(mcos));
  mcos[start] = 0;

  while (!pq.empty()) {
    const pii tmp = pq.top();
    pq.pop();

    const int now = tmp.se;

    if (mcos[now] < tmp.fi)
      continue;

    for (int i = 0; i < G[now].size(); ++i) {
      const int newcost = G[now][i].fi + tmp.fi;
      const int next = G[now][i].se;

      if (newcost < mcos[next]) {
        mcos[next] = newcost;
        pq.push(pii(newcost, next));
      }
    }
  }
  return;
}

int main() {
  cin >> N;
  int k, u, v, c;

  for (int i = 0; i < N; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      G[u].push_back(make_pair(c, v));
    }
  }
  dijkstra(0);
  for (int i = 0; i < N; i++) {
    cout << i << " " << mcos[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

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

using namespace std;

typedef pair<int, int> pii;
#define INF 0x3f3f3f3f
#define fi first
#define se second

int mcos[105];
vector<pii> G[105];
int N;

void dijkstra(int start) {
  priority_queue<pii, vector<pii>, greater<pii>> pq;

  pq.push(pii(0, start));
  memset(mcos, INF, sizeof(mcos));
  mcos[start] = 0;

  while (!pq.empty()) {
    const pii tmp = pq.top();
    pq.pop();

    const int now = tmp.se;

    if (mcos[now] < tmp.fi)
      continue;

    for (int i = 0; i < G[now].size(); ++i) {
      const int newcost = G[now][i].fi + tmp.fi;
      const int next = G[now][i].se;

      if (newcost < mcos[next]) {
        mcos[next] = newcost;
        pq.push(pii(newcost, next));
      }
    }
  }
  return;
}

int main() {
  cin >> N;
  int k, u, v, c;

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

#include <bits/stdc++.h>
#define INF 1000000000
#define MAX_N 10000
using namespace std;
int n;
int d[MAX_N];

struct edge {
  int to, cost;
  edge(int to_, int cost_) : to(to_), cost(cost_) {}
};
typedef pair<int, int> P;
vector<edge> G[MAX_N];

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

  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() {
  cin >> n;
  for (int i = 0, u, k; i < n; i++) {
    cin >> u >> k;
    for (int j = 0, v, c; j < k; j++) {
      cin >> v >> c;
      G[u].push_back(edge(v, c));
    }
  }
  Dijkstra(0);
  for (int i = 0; i < n; i++) {
    cout << i << ' ' << d[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define INF 1000000000
#define MAX_N 100
using namespace std;
int n;
int d[MAX_N];

struct edge {
  int to, cost;
  edge(int to_, int cost_) : to(to_), cost(cost_) {}
};
typedef pair<int, int> P;
vector<edge> G[MAX_N];

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

  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() {
  cin >> n;
  for (int i = 0, u, k; i < n; i++) {
    cin >> u >> k;
    for (int j = 0, v, c; j < k; j++) {
      cin >> v >> c;
      G[u].push_back(edge(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 <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define int(x)                                                                 \\
  int x;                                                                       \\
  scanf("%d", &x)
#define input(x) scanf("%d", &x)
#define rep(x, n) for (int x = 0; x < n; x++)
#define _br printf("\\n")
#define INF 2000000000

vector<pair<int, int>> PathList[10000];
int d[10000];
bool complete[10000];

void dijkstra(int n, vector<pair<int, int>> PathList[]) {
  rep(i, n) {
    d[i] = INF;
    complete[i] = false;
  }
  d[0] = 0;

  int count = 0;

  while (count != n) {
    int mind = INF;
    int mindi = 0;

    // select
    rep(i, n) {
      if (!complete[i] && d[i] < mind) {
        mind = d[i];
        mindi = i;
      }
    }

    complete[mindi] = true;
    count++;

    // update
    rep(i, PathList[mindi].size()) {
      if (PathList[mindi][i].second + d[mindi] < d[PathList[mindi][i].first]) {
        d[PathList[mindi][i].first] = PathList[mindi][i].second + d[mindi];
      }
    }
  }
}

int main() {
  int(n);
  rep(i, n) {
    int(k);
    int(num);
    rep(j, num) {
      int(s);
      int(t);
      PathList[i].push_back(make_pair(s, t));
    }
  }

  dijkstra(n, PathList);

  rep(i, n) { printf("%d %d\\n", i, d[i]); }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define int(x)                                                                 \\
  int x;                                                                       \\
  scanf("%d", &x)
#define input(x) scanf("%d", &x)
#define rep(x, n) for (int x = 0; x < n; x++)
#define _br printf("\\n")
#define INF 2000000000

vector<pair<int, int>> PathList[100];
int d[100];
bool complete[100];

void dijkstra(int n, vector<pair<int, int>> PathList[]) {
  rep(i, n) {
    d[i] = INF;
    complete[i] = false;
  }
  d[0] = 0;

  int count = 0;

  while (count != n) {
    int mind = INF;
    int mindi = 0;

    // select
    rep(i, n) {
      if (!complete[i] && d[i] < mind) {
        mind = d[i];
        mindi = i;
      }
    }

    complete[mindi] = true;
    count++;

    // update
    rep(i, PathList[mindi].size()) {
      if (PathList[mindi][i].second + d[mindi] < d[PathList[mindi][i].first]) {
        d[PathList[mindi][i].first] = PathList[mindi][i].second + d[mindi];
      }
    }
  }
}

int main() {
  int(n);
  rep(i, n) {
    int(k);
    int(num);
    rep(j, num) {
      int(s);
      int(t);
      PathList[i].push_back(make_pair(s, t));
    }
  }

  dijkstra(n, PathList);

  rep(i, n) { printf("%d %d\\n", i, d[i]); }

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define P pair<int, int> // cost to
using namespace std;

vector<P> rinsetu[10000];
int mincost[10000];
signed main() {
  int a;
  cin >> a;
  for (int b = 0; b < a; b++) {
    int c, d;
    cin >> c >> d;
    for (int e = 0; e < d; e++) {
      int f, g;
      scanf("%d%d", &f, &g);
      rinsetu[c].push_back(P(g, f));
    }
  }
  fill(mincost, mincost + a, 1 << 29);
  mincost[0] = 0;
  priority_queue<P, vector<P>, greater<P>> Q;
  Q.push(P(0, 0));
  while (Q.size()) {
    P t = Q.top();
    Q.pop();
    if (t.first > mincost[t.second])
      continue;
    for (P i : rinsetu[t.second]) {
      if (mincost[i.second] > t.first + i.first) {
        mincost[i.second] = t.first + i.first;
        Q.push(P(t.first + i.first, i.second));
      }
    }
  }
  for (int i = 0; i < a; i++) {
    cout << i << " " << mincost[i] << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define P pair<int, int> // cost to
using namespace std;

vector<P> rinsetu[100];
int mincost[100];
signed main() {
  int a;
  cin >> a;
  for (int b = 0; b < a; b++) {
    int c, d;
    cin >> c >> d;
    for (int e = 0; e < d; e++) {
      int f, g;
      scanf("%d%d", &f, &g);
      rinsetu[c].push_back(P(g, f));
    }
  }
  fill(mincost, mincost + a, 1 << 29);
  mincost[0] = 0;
  priority_queue<P, vector<P>, greater<P>> Q;
  Q.push(P(0, 0));
  while (Q.size()) {
    P t = Q.top();
    Q.pop();
    if (t.first > mincost[t.second])
      continue;
    for (P i : rinsetu[t.second]) {
      if (mincost[i.second] > t.first + i.first) {
        mincost[i.second] = t.first + i.first;
        Q.push(P(t.first + i.first, i.second));
      }
    }
  }
  for (int i = 0; i < a; i++) {
    cout << i << " " << mincost[i] << endl;
  }
}
Problem p02243 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1},
          dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

typedef pair<int, int> P;

int main() {
  int N;
  cin >> N;
  std::vector<vector<int>> G(N, vector<int>());
  std::vector<vector<int>> dist(N, vector<int>());
  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;
      G[u].push_back(v);
      dist[u].push_back(c);
    }
  }

  std::vector<int> d(N, 100000001);
  priority_queue<P, vector<P>, greater<P>> q;
  d[0] = 0;
  q.push(P(0, 0));

  while (!q.empty()) {
    P u = q.top();
    q.pop();
    int v = u.second;
    if (d[v] < u.first) {
      continue;
    }
    for (int i = 0; i < G[v].size(); i++) {
      if (d[G[v][i]] > d[v] + dist[v][i]) {
        d[G[v][i]] = d[v] + dist[v][i];
        q.push(P(d[G[v][i]], G[v][i]));
      }
    }
  }

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1},
          dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

int main() {
  int N;
  cin >> N;
  std::vector<vector<int>> G(N, vector<int>(N, 100000000));
  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;
      G[u][v] = c;
    }
  }

  for (int i = 0; i < N; i++) {
    G[i][i] = 0;
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        G[i][j] = std::min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }

  for (int i = 0; i < N; i++) {
    cout << i << " " << G[0][i] << endl;
  }
  return 0;
}
Problem p02243 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i, a, b) for (i = a; i < b; i++)
#define rloop(i, a, b) for (i = a; i >= b; i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define vs vector<string>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int N = 10000;

int n;
vector<vector<pair<int, int>>> adj(N, vector<pair<int, int>>());
vi d(N, inf);

void dijkstra();

int main() {
  int k, u, v, c, i, j;
  cin >> n;
  loop(i, 0, n) {
    cin >> u >> k;
    loop(j, 0, k) {
      cin >> v >> c;
      adj[u].push_back(make_pair(c, v));
    }
  }
  dijkstra();
  loop(i, 0, n) { cout << i << " " << ((d[i] == inf) ? -1 : d[i]) << endl; }
}

void dijkstra() {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  int i;
  vi color(n, 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) {
      continue;
    }
    loop(i, 0, adj[u].size()) {
      int v = adj[u][i].second;
      if (color[v] != BLACK && d[v] > d[u] + adj[u][i].first) {
        d[v] = d[u] + adj[u][i].first;
        pq.push(make_pair(d[v], v));
        color[v] = GRAY;
      }
    }
  }
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i, a, b) for (i = a; i < b; i++)
#define rloop(i, a, b) for (i = a; i >= b; i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define vs vector<string>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int N = 10000;

int n;
vii m(N, vi(N));
vi d(N, inf);

void dijkstra();

int main() {
  int i, j;
  cin >> n;
  int u, k, v, c;
  loop(i, 0, n) {
    loop(j, 0, n) { m[i][j] = inf; }
  }
  loop(i, 0, n) {
    cin >> u >> k;
    loop(j, 0, k) {
      cin >> v >> c;
      m[u][v] = c;
    }
  }
  dijkstra();
  loop(i, 0, n) { cout << i << " " << d[i] << endl; }
}

void dijkstra() {
  int i;
  d[0] = 0;
  vi color(n, WHITE);
  color[0] = BLACK;
  int u = 0, v;
  while (1) {
    int minv = inf;
    loop(i, 0, n) {
      if (color[i] != BLACK) {
        d[i] = min(d[i], d[u] + m[u][i]);
        if (minv > d[i]) {
          minv = d[i];
          v = i;
        }
      }
    }
    if (minv == inf) {
      break;
    }
    color[v] = BLACK;
    u = v;
  }
}