prithivMLmods/Coder-Stat huggingface dataset:
Problem p02358 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int main() {
  int n;
  cin >> n;
  vvi in(n, vi(4));
  rep(i, n) rep(j, 4) cin >> in[i][j];
  vi x, y;
  rep(i, n) rep(j, 4) loop(k, -1, 2) if (j % 2) y.pb(in[i][j] + k);
  else x.pb(in[i][j] + k);
  sort(all(x));
  sort(all(y));
  x.erase(unique(all(x)), x.end());
  y.erase(unique(all(y)), y.end());

  vvi tmp = in;
  rep(i, n) rep(j, 4) if (j % 2) tmp[i][j] =
      find(all(y), tmp[i][j]) - y.begin();
  else tmp[i][j] = find(all(x), tmp[i][j]) - x.begin();
  vvi field(x.size(), vi(y.size()));
  rep(i, n) loop(j, tmp[i][0], tmp[i][2]) loop(k, tmp[i][1], tmp[i][3])
      field[j][k] = true;
  ll out = 0;
  rep(i, x.size()) rep(j, y.size()) if (field[i][j]) out +=
      (ll)(x[i + 1] - x[i]) * (y[j + 1] - y[j]);
  cout << out << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int main() {
  int n;
  cin >> n;
  vvi in(n, vi(4));
  rep(i, n) rep(j, 4) cin >> in[i][j];
  vi x, y;
  rep(i, n) rep(j, 4) if (j % 2) y.pb(in[i][j]);
  else x.pb(in[i][j]);
  sort(all(x));
  sort(all(y));
  x.erase(unique(all(x)), x.end());
  y.erase(unique(all(y)), y.end());

  vvi tmp = in;
  rep(i, n) rep(j, 4) if (j % 2) tmp[i][j] =
      find(all(y), tmp[i][j]) - y.begin();
  else tmp[i][j] = find(all(x), tmp[i][j]) - x.begin();
  vvi field(x.size(), vi(y.size()));
  rep(i, n) loop(j, tmp[i][0], tmp[i][2]) loop(k, tmp[i][1], tmp[i][3])
      field[j][k] = true;
  ll out = 0;
  rep(i, x.size()) rep(j, y.size()) if (field[i][j]) out +=
      (ll)(x[i + 1] - x[i]) * (y[j + 1] - y[j]);
  cout << out << endl;
}
Problem p02360 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>

struct Square {
  int x1, y1, x2, y2;
};
std::istream &operator>>(std::istream &is, Square &s) {
  return is >> s.x1 >> s.y1 >> s.x2 >> s.y2;
}
int main() {
  int n;
  std::cin >> n;
  constexpr int max_coord = 4;
  std::vector<std::vector<int>> map(max_coord + 1,
                                    std::vector<int>(max_coord + 1, 0));
  Square s;
  for (auto i = 0; i < n; ++i) {
    std::cin >> s;
    map[s.x1][s.y1]++;
    map[s.x2][s.y1]--;
    map[s.x1][s.y2]--;
    map[s.x2][s.y2]++;
  }
  for (auto i = 1; i < map.size(); ++i) {
    for (auto j = 0; j < map[i].size(); ++j) {
      map[i][j] += map[i - 1][j];
    }
  }
  int max = 0;
  for (auto i = 0; i < map.size(); ++i) {
    if (max < map[i][0])
      max = map[i][0];
    for (auto j = 1; j < map[i].size(); ++j) {
      map[i][j] += map[i][j - 1];
      if (max < map[i][j])
        max = map[i][j];
    }
  }
  std::cout << max << std::endl;
}


Fixed submission:
#include <iostream>
#include <vector>

struct Square {
  int x1, y1, x2, y2;
};
std::istream &operator>>(std::istream &is, Square &s) {
  return is >> s.x1 >> s.y1 >> s.x2 >> s.y2;
}
int main() {
  int n;
  std::cin >> n;
  constexpr int max_coord = 1000;
  std::vector<std::vector<int>> map(max_coord + 1,
                                    std::vector<int>(max_coord + 1, 0));
  Square s;
  for (auto i = 0; i < n; ++i) {
    std::cin >> s;
    map[s.x1][s.y1]++;
    map[s.x2][s.y1]--;
    map[s.x1][s.y2]--;
    map[s.x2][s.y2]++;
  }
  for (auto i = 1; i < map.size(); ++i) {
    for (auto j = 0; j < map[i].size(); ++j) {
      map[i][j] += map[i - 1][j];
    }
  }
  int max = 0;
  for (auto i = 0; i < map.size(); ++i) {
    if (max < map[i][0])
      max = map[i][0];
    for (auto j = 1; j < map[i].size(); ++j) {
      map[i][j] += map[i][j - 1];
      if (max < map[i][j])
        max = map[i][j];
    }
  }
  std::cout << max << std::endl;
}
Problem p02361 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#define pb push_back
#define INF 1010001000
#define loop(i, n) for (int i = 0; i < n; i++)

typedef pair<int, int> i_i;
typedef struct edge {
  int st, en, cst;
} Edge;

int main() {
  int v, e, r;
  cin >> v >> e >> r;

  vector<vector<i_i>> G(v);
  vector<int> ans(v, INF);

  loop(i, e) {
    int st, en, d;
    cin >> st >> en >> d;
    G[st].pb(i_i(d, en));
  }

  priority_queue<i_i, vector<i_i>, greater<i_i>> pq;
  pq.push(i_i(0, r));
  ans[r] = 0;
  while (!pq.empty()) {
    i_i p = pq.top();
    pq.pop();
    int u = p.second;
    if (ans[u] < p.first) {
      continue;
    }
    for (i_i i : G[u]) {
      if (ans[i.second] > ans[u] + i.first) {
        ans[i.second] = ans[u] + i.first;
        pq.push(i_i(ans[i.second], i.second));
      }
    }
  }

  loop(i, v) {
    if (ans[i] != INF) {
      cout << ans[i] << endl;
    } else {
      cout << "INF" << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

#define pb push_back
#define INF 1010001000
#define loop(i, n) for (int i = 0; i < n; i++)

typedef pair<int, int> i_i;
typedef struct edge {
  int st, en, cst;
} Edge;

int main() {
  int v, e, r;
  cin >> v >> e >> r;

  vector<vector<i_i>> G(v);
  vector<int> ans(v, INF);

  loop(i, e) {
    int st, en, d;
    cin >> st >> en >> d;
    G[st].pb(i_i(d, en));
  }

  priority_queue<i_i, vector<i_i>, greater<i_i>> pq;
  pq.push(i_i(0, r));
  ans[r] = 0;
  while (!pq.empty()) {
    i_i p = pq.top();
    pq.pop();
    int u = p.second;
    if (ans[u] < p.first) {
      continue;
    }
    for (int j = 0; j < G[u].size(); j++) {
      i_i i = G[u][j];
      if (ans[i.second] > ans[u] + i.first) {
        ans[i.second] = ans[u] + i.first;
        pq.push(i_i(ans[i.second], i.second));
      }
    }
  }

  loop(i, v) {
    if (ans[i] != INF) {
      cout << ans[i] << endl;
    } else {
      cout << "INF" << endl;
    }
  }
  return 0;
}
Problem p02361 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;

#define MAXN 100010
// d,edge,g,P,q
lint d[MAXN];
struct edge {
  int to;
  lint cost;
};
vector<edge> g[MAXN];
typedef pair<lint, int> P;
priority_queue<P, vector<P>, greater<P>> q;

void pfs(int s) {
  d[s] = 0;
  q.push({0, s});
  lint cd, v;
  while (q.size()) {
    cd = q.top().first;
    v = q.top().second;
    q.pop();
    if (cd > d[v])
      continue;
    for (edge &e : g[v])
      if (d[e.to] > cd + e.cost) {
        d[e.to] = cd + e.cost;
        q.push({d[e.to], e.to});
      }
  }
}

#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  lint v, e, r;
  cin >> v >> e >> r;
  rep(i, v) d[i] = INT_MAX;
  int a, b;
  lint c;
  rep(i, e) {
    cin >> a >> b >> c;
    g[a].push_back({b, c});
  }
  pfs(r);
  rep(i, v) {
    if (d[i] == INT_MAX)
      cout << "INF¥n";
    else
      cout << d[i] << endl;
  }
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;

#define MAXN 100010
// d,edge,g,P,q
lint d[MAXN];
struct edge {
  int to;
  lint cost;
};
vector<edge> g[MAXN];
typedef pair<lint, int> P;
priority_queue<P, vector<P>, greater<P>> q;

void pfs(int s) {
  d[s] = 0;
  q.push({0, s});
  lint cd, v;
  while (q.size()) {
    cd = q.top().first;
    v = q.top().second;
    q.pop();
    if (cd > d[v])
      continue;
    for (edge &e : g[v])
      if (d[e.to] > cd + e.cost) {
        d[e.to] = cd + e.cost;
        q.push({d[e.to], e.to});
      }
  }
}

#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
  lint v, e, r;
  cin >> v >> e >> r;
  rep(i, v) d[i] = INT_MAX;
  int a, b;
  lint c;
  rep(i, e) {
    cin >> a >> b >> c;
    g[a].push_back({b, c});
  }
  pfs(r);
  rep(i, v) {
    if (d[i] == INT_MAX)
      cout << "INF" << endl;
    else
      cout << d[i] << endl;
  }
}
Problem p02361 (C++)

Buggy submission (status: Runtime Error):
#include <climits>
#include <iostream>
#include <queue>
#include <vector>
#define INF 1e+18
using namespace std;

struct Edge {
  int trg;
  long long w;
};

struct vertex {
  int v;
  long long w;
  bool operator<(const vertex &x) const { return w < x.w; }
  bool operator>(const vertex &x) const { return w > x.w; }
};

const int MAX_V = 10000;
vector<vector<Edge>> graph(MAX_V);
vector<long long> min_cost(MAX_V, INF);
vector<bool> used(MAX_V, false);

void dijkstra(int s, int V) {
  min_cost[s] = 0;

  priority_queue<vertex, vector<vertex>, greater<vertex>> pq;
  pq.push(vertex{s, 0});
  while (!pq.empty()) {
    vertex ver = pq.top();
    pq.pop();
    int v = ver.v;
    if (used[v])
      continue;
    used[v] = true;
    min_cost[v] = ver.w;

    for (int i = 0; i < graph[v].size(); i++) {
      if (!used[graph[v][i].trg]) {
        pq.push(vertex{graph[v][i].trg, min_cost[v] + graph[v][i].w});
      }
    }
  }
}

void print_array(vector<long long> &array, int node) {
  for (int i = 0; i < node; i++) {
    if (array[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << array[i] << endl;
    }
  }
}

int main() {

  int V, E, r;
  cin >> V >> E >> r;
  int s, t, d;
  for (int i = 0; i < E; i++) {
    cin >> s >> t >> d;
    graph[s].push_back(Edge{t, d});
  }
  dijkstra(r, V);
  print_array(min_cost, V);

  return 0;
}

Fixed submission:
#include <climits>
#include <iostream>
#include <queue>
#include <vector>
#define INF 1e+18
using namespace std;

struct Edge {
  int trg;
  long long w;
};

struct vertex {
  int v;
  long long w;
  bool operator<(const vertex &x) const { return w < x.w; }
  bool operator>(const vertex &x) const { return w > x.w; }
};

const int MAX_V = 100000;
vector<vector<Edge>> graph(MAX_V);
vector<long long> min_cost(MAX_V, INF);
vector<bool> used(MAX_V, false);

void dijkstra(int s, int V) {
  min_cost[s] = 0;

  priority_queue<vertex, vector<vertex>, greater<vertex>> pq;
  pq.push(vertex{s, 0});
  while (!pq.empty()) {
    vertex ver = pq.top();
    pq.pop();
    int v = ver.v;
    if (used[v])
      continue;
    used[v] = true;
    min_cost[v] = ver.w;

    for (int i = 0; i < graph[v].size(); i++) {
      if (!used[graph[v][i].trg]) {
        pq.push(vertex{graph[v][i].trg, min_cost[v] + graph[v][i].w});
      }
    }
  }
}

void print_array(vector<long long> &array, int node) {
  for (int i = 0; i < node; i++) {
    if (array[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << array[i] << endl;
    }
  }
}

int main() {

  int V, E, r;
  cin >> V >> E >> r;
  int s, t, d;
  for (int i = 0; i < E; i++) {
    cin >> s >> t >> d;
    graph[s].push_back(Edge{t, d});
  }
  dijkstra(r, V);
  print_array(min_cost, V);

  return 0;
}
Problem p02361 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define MAX_V 1000
#define MAX_E 2000
#define INF 1e9
using namespace std;
struct edge {
  int from, to, cost;
};
edge es[MAX_E];
int d[MAX_V];
int V;
int E;

bool find_negative_loop(int s) {
  d[s] = 0;
  int count = 0;
  while (true) {
    bool update = false;
    count++;
    for (int i = 0; i < MAX_E; i++) {

      if (d[es[i].from] != INF && d[es[i].to] > d[es[i].from] + es[i].cost) {
        if (count == V) {
          return true;
        }
        d[es[i].to] = d[es[i].from] + es[i].cost;
        update = true;
      }
    }
    if (update == false) {
      break;
    }
  }
  return false;
}

int main() {

  int r;
  cin >> V >> E >> r;
  for (int i = 0; i < MAX_V; i++) {
    d[i] = INF;
  }
  for (int i = 0; i < E; i++) {
    cin >> es[i].from >> es[i].to >> es[i].cost;
  }
  if (find_negative_loop(r)) {
    cout << "NEGATIVE CYCLE" << endl;
  } else {
    for (int i = 0; i < V; i++) {
      if (d[i] == INF) {
        cout << "INF" << endl;
      } else {
        cout << d[i] << endl;
      }
    }
  }

  return 0;
}


Fixed submission:
#include <iostream>
#define MAX_V 100000
#define MAX_E 500000
#define INF 1e9
using namespace std;
struct edge {
  int from, to, cost;
};
edge es[MAX_E];
int d[MAX_V];
int V;
int E;

bool find_negative_loop(int s) {
  d[s] = 0;
  int count = 0;
  while (true) {
    bool update = false;
    count++;
    for (int i = 0; i < MAX_E; i++) {

      if (d[es[i].from] != INF && d[es[i].to] > d[es[i].from] + es[i].cost) {
        if (count == V) {
          return true;
        }
        d[es[i].to] = d[es[i].from] + es[i].cost;
        update = true;
      }
    }
    if (update == false) {
      break;
    }
  }
  return false;
}

int main() {

  int r;
  cin >> V >> E >> r;
  for (int i = 0; i < MAX_V; i++) {
    d[i] = INF;
  }
  for (int i = 0; i < E; i++) {
    cin >> es[i].from >> es[i].to >> es[i].cost;
  }
  if (find_negative_loop(r)) {
    cout << "NEGATIVE CYCLE" << endl;
  } else {
    for (int i = 0; i < V; i++) {
      if (d[i] == INF) {
        cout << "INF" << endl;
      } else {
        cout << d[i] << endl;
      }
    }
  }

  return 0;
}
Problem p02361 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef pair<long long, long long> P;
int v, e, r;
struct edge {
  int to;
  long long cost;
  edge(int _to, long long _cost) : to(_to), cost(_cost) {}
};
vector<edge> G[100010];
long long d[10010];

void dijkstra(int start) {
  priority_queue<P, vector<P>, greater<P>> que;
  for (int i = 0; i < v; i++)
    d[i] = 1e12;
  d[start] = 0;
  que.push(P(d[r], r));

  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 >> v >> e >> r;
  for (int i = 0; i < e; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    G[s].push_back(edge(t, d));
  }

  dijkstra(r);
  for (int i = 0; i < v; i++) {
    if (d[i] != 1e12)
      cout << d[i] << endl;
    else
      cout << "INF" << endl;
  }
}

Fixed submission:
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef pair<long long, long long> P;
int v, e, r;
struct edge {
  int to;
  long long cost;
  edge(int _to, long long _cost) : to(_to), cost(_cost) {}
};
vector<edge> G[100010];
long long d[100100];

void dijkstra(int start) {
  priority_queue<P, vector<P>, greater<P>> que;
  for (int i = 0; i < v; i++)
    d[i] = 1e12;
  d[start] = 0;
  que.push(P(d[r], r));

  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 >> v >> e >> r;
  for (int i = 0; i < e; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    G[s].push_back(edge(t, d));
  }

  dijkstra(r);
  for (int i = 0; i < v; i++) {
    if (d[i] != 1e12)
      cout << d[i] << endl;
    else
      cout << "INF" << endl;
  }
}
Problem p02361 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
#define MAX_V 100001
#define INF (1e9 + 1)

int V, E, r, a, b, c;
vector<int> G_t[MAX_V];
vector<int> G_c[MAX_V];

int d[MAX_V];
void dijkstra() {
  int i;
  for (i = 0; i < MAX_V; i++)
    d[i] = INF;
  d[r] = 0;
  priority_queue<pair<int, int>> Q;
  Q.push(make_pair(-d[r], r));
  while (!Q.empty()) {
    pair<int, int> p = Q.top();
    Q.top();
    int pos = p.second, cost = -p.first;
    if (cost > d[pos])
      continue;
    for (i = 0; i < G_t[pos].size(); i++) {
      int to = G_t[pos][i];
      int newcost = cost + G_c[pos][i];
      if (newcost < d[to]) {
        d[to] = newcost;
        Q.push(make_pair(-d[to], to));
      }
    }
  }
  for (i = 0; i < V; i++) {
    if (d[i] == INF)
      printf("INF\n");
    else
      printf("%d\n", d[i]);
  }
}
int main() {
  int i;
  scanf("%d%d%d", &V, &E, &r);
  for (i = 0; i < E; i++) {
    scanf("%d%d%d", &a, &b, &c);
    G_t[a].push_back(b);
    G_c[a].push_back(c);
  }
  dijkstra();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
#define MAX_V 100001
#define INF (1e9 + 1)

int V, E, r, a, b, c;
vector<int> G_t[MAX_V];
vector<int> G_c[MAX_V];

int d[MAX_V];
void dijkstra() {
  int i;
  for (i = 0; i < MAX_V; i++)
    d[i] = INF;
  d[r] = 0;
  priority_queue<pair<int, int>> Q;
  Q.push(make_pair(-d[r], r));
  while (!Q.empty()) {
    pair<int, int> p = Q.top();
    Q.pop();
    int pos = p.second, cost = -p.first;
    if (cost > d[pos])
      continue;
    for (i = 0; i < G_t[pos].size(); i++) {
      int to = G_t[pos][i];
      int newcost = cost + G_c[pos][i];
      if (newcost < d[to]) {
        d[to] = newcost;
        Q.push(make_pair(-d[to], to));
      }
    }
  }
  for (i = 0; i < V; i++) {
    if (d[i] == INF)
      printf("INF\n");
    else
      printf("%d\n", d[i]);
  }
}
int main() {
  int i;
  scanf("%d%d%d", &V, &E, &r);
  for (i = 0; i < E; i++) {
    scanf("%d%d%d", &a, &b, &c);
    G_t[a].push_back(b);
    G_c[a].push_back(c);
  }
  dijkstra();
  return 0;
}
Problem p02361 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
vector<pair<int, int>> x[500];
int n, m, s, a, b, c, dist[500], dist2[500][500];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    Q;
void dijkstra(int V, int E, int s) {
  for (int i = 0; i < V; i++)
    dist[i] = 999999999;
  dist[s] = 0;
  Q.push(make_pair(0, s));
  while (!Q.empty()) {
    int a1 = Q.top().first, a2 = Q.top().second;
    Q.pop();
    for (int i = 0; i < x[a2].size(); i++) {
      if (dist[x[a2][i].first] > a1 + x[a2][i].second) {
        dist[x[a2][i].first] = a1 + x[a2][i].second;
        Q.push(make_pair(dist[x[a2][i].first], x[a2][i].first));
      }
    }
  }
}
int main() {
  int s;
  cin >> n >> m;
  cin >> s;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    x[a].push_back(make_pair(b, c));
  }
  /*for(int i=0;i<n;i++){
          dijkstra(n,m,i);
          for(int j=0;j<n;j++)dist2[i][j]=dist[j];
  }
  int q;cin>>q;
  for(int i=0;i<q;i++){
          cin>>a>>b;a--;b--;
          if(dist2[a][b]>=999999999)cout<<"-1"<<endl;
          else cout<<dist2[a][b]<<endl;
  }*/
  dijkstra(n, m, s);
  for (int i = 0; i < n; i++) {
    if (dist[i] == 999999999)
      cout << "INF" << endl;
    else
      cout << dist[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
vector<pair<int, int>> x[300000];
int n, m, s, a, b, c, dist[300000], dist2[500][500];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    Q;
void dijkstra(int V, int E, int s) {
  for (int i = 0; i < V; i++)
    dist[i] = 999999999;
  dist[s] = 0;
  Q.push(make_pair(0, s));
  while (!Q.empty()) {
    int a1 = Q.top().first, a2 = Q.top().second;
    Q.pop();
    for (int i = 0; i < x[a2].size(); i++) {
      if (dist[x[a2][i].first] > a1 + x[a2][i].second) {
        dist[x[a2][i].first] = a1 + x[a2][i].second;
        Q.push(make_pair(dist[x[a2][i].first], x[a2][i].first));
      }
    }
  }
}
int main() {
  int s;
  cin >> n >> m;
  cin >> s;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    x[a].push_back(make_pair(b, c));
  }
  /*for(int i=0;i<n;i++){
          dijkstra(n,m,i);
          for(int j=0;j<n;j++)dist2[i][j]=dist[j];
  }
  int q;cin>>q;
  for(int i=0;i<q;i++){
          cin>>a>>b;a--;b--;
          if(dist2[a][b]>=999999999)cout<<"-1"<<endl;
          else cout<<dist2[a][b]<<endl;
  }*/
  dijkstra(n, m, s);
  for (int i = 0; i < n; i++) {
    if (dist[i] == 999999999)
      cout << "INF" << endl;
    else
      cout << dist[i] << endl;
  }
  return 0;
}
Problem p02361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<pii> vpii;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define rrep2(i, a, b) for (int i = (a); i > b; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()

const int mod = 1e9 + 7;
const ll INF = 1 << 30;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int V, E, r;
struct edge {
  int to, cost;
};
vector<edge> g[100000 + 5];
int d[10000 + 5];

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

  while (!que.empty()) {
    pii 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(pii(d[e.to], e.to));
      }
    }
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> V >> E >> r;
  rep(i, E) {
    int s, t, d;
    cin >> s >> t >> d;
    g[s].pb(edge{t, d});
  }
  dijkstra(r);
  rep(i, V) {
    if (d[i] == INF)
      cout << "INF" << endl;
    else
      cout << d[i] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<pii> vpii;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define rrep2(i, a, b) for (int i = (a); i > b; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()

const int mod = 1e9 + 7;
const ll INF = 1 << 30;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int V, E, r;
struct edge {
  int to, cost;
};
vector<edge> g[100000 + 5];
int d[100000 + 5];

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

  while (!que.empty()) {
    pii 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(pii(d[e.to], e.to));
      }
    }
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> V >> E >> r;
  rep(i, E) {
    int s, t, d;
    cin >> s >> t >> d;
    g[s].pb(edge{t, d});
  }
  dijkstra(r);
  rep(i, V) {
    if (d[i] == INF)
      cout << "INF" << endl;
    else
      cout << d[i] << endl;
  }
}
Problem p02361 (Python)

Buggy submission (status: Runtime Error):
import sys
import queue


class Dijkstra:
    class Edge:
        def __init__(self, end, cost):
            self.to = end
            self.cost = cost

    def __init__(self, node_size, inf):
        self._node = node_size
        self._graph = [[] for _ in range(self._node)]
        self.inf = inf
        self.dist = [self.inf for _ in range(self._node)]

    def add_edge(self, st, ed, cs):
        self._graph[st].append(self.Edge(ed, cs))

    def solve(self, start):
        que = queue.PriorityQueue()
        self.dist[start] = 0
        que.put((0, start))
        while que:
            cur_cost, cur_vertex = que.get()
            if self.dist[cur_vertex] < cur_cost:
                continue
            for e in self._graph[cur_vertex]:
                if self.dist[e.to] > cur_cost + e.cost:
                    self.dist[e.to] = cur_cost + e.cost
                    que.put((self.dist[e.to], e.to))


if __name__ == "__main__":
    V, E, r = map(int, sys.stdin.readline().split())
    dk = Dijkstra(V, 10**10)
    for i in range(E):
        s, t, d = map(int, sys.stdin.readline().split())
        dk.add_edge(s, t, d)
    dk.solve(r)
    for value in dk.dist:
        if value == dk.inf:
            print("INF")
        else:
            print(value)


Fixed submission:
import sys
import queue


class Dijkstra:
    class Edge:
        def __init__(self, end, cost):
            self.to = end
            self.cost = cost

    def __init__(self, node_size, inf):
        self._node = node_size
        self._graph = [[] for _ in range(self._node)]
        self.inf = inf
        self.dist = [self.inf for _ in range(self._node)]

    def add_edge(self, st, ed, cs):
        self._graph[st].append(self.Edge(ed, cs))

    def solve(self, start):
        que = queue.PriorityQueue()
        self.dist[start] = 0
        que.put((0, start))
        while not que.empty():
            cur_cost, cur_vertex = que.get()
            if self.dist[cur_vertex] < cur_cost:
                continue
            for e in self._graph[cur_vertex]:
                if self.dist[e.to] > cur_cost + e.cost:
                    self.dist[e.to] = cur_cost + e.cost
                    que.put((self.dist[e.to], e.to))


if __name__ == "__main__":
    V, E, r = map(int, sys.stdin.readline().split())
    dk = Dijkstra(V, 10**10)
    for i in range(E):
        s, t, d = map(int, sys.stdin.readline().split())
        dk.add_edge(s, t, d)
    dk.solve(r)
    for value in dk.dist:
        if value == dk.inf:
            print("INF")
        else:
            print(value)
Problem p02361 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

using namespace std;

const int Inf = 10000 * 100000 + 100;
int a, b, V, E, R, S, Start[500000 + 10], To[500000 + 10], Dis[500000 + 10],
    N[500000 + 10];
int Ans[100000 + 10];

priority_queue<pair<int, int>> Q;

// first is the distance from R, second is the number of V
// redefine the operator '<' to let the priority_queue making the smallest in
// the first place
bool operator<(pair<int, int> a, pair<int, int> b) {
  return (a.first == b.first) ? a.second > b.second : a.first > b.first;
}

int main() {
  cin >> V >> E >> R;
  for (int i = 1; i <= E; i++) {
    cin >> S >> To[i] >> Dis[i];
    N[i] = Start[S];
    Start[S] = i;
  }

  fill(Ans, Ans + 100010, Inf);
  Ans[R] = 0;
  Q.push(make_pair(0, R));

  while (!Q.empty()) {
    a = Q.top().first;
    b = Q.top().second;
    Q.pop();
    if (Ans[b] == a) {
      for (int i = Start[b]; i; i = N[i]) {
        int t = To[i];
        if (a + Dis[i] < Ans[t]) {
          Ans[t] = a + Dis[i];
          Q.push(make_pair(Ans[t], t));
        }
      }
    }
  }

  for (int i = 0; i < V; i++) {
    if (Ans[i] < Inf) {
      cout << Ans[i] << endl;
    } else {
      cout << "INF" << endl;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>

using namespace std;

const int Inf = 10000 * 100000 + 100;
int a, b, V, E, R, S, Start[500000 + 10], To[500000 + 10], Dis[500000 + 10],
    N[500000 + 10];
int Ans[100000 + 10];

priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    Q;

int main() {
  cin >> V >> E >> R;
  for (int i = 1; i <= E; i++) {
    cin >> S >> To[i] >> Dis[i];
    N[i] = Start[S];
    Start[S] = i;
  }

  fill(Ans, Ans + 100010, Inf);
  Ans[R] = 0;
  Q.push(make_pair(0, R));

  while (!Q.empty()) {
    a = Q.top().first;
    b = Q.top().second;
    Q.pop();
    if (Ans[b] == a) {
      for (int i = Start[b]; i; i = N[i]) {
        int t = To[i];
        if (a + Dis[i] < Ans[t]) {
          Ans[t] = a + Dis[i];
          Q.push(make_pair(Ans[t], t));
        }
      }
    }
  }

  for (int i = 0; i < V; i++) {
    if (Ans[i] < Inf) {
      cout << Ans[i] << endl;
    } else {
      cout << "INF" << endl;
    }
  }
}
Problem p02361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct node {
  int id;
  ll dp;
};

struct edge {
  int des;
  ll w;
};

int n, m;
vector<edge> adj[10007];
ll Min[100007];
bool mark[100007];

bool operator<(node a, node b) { return a.dp >= b.dp; }

void prim(int u) {
  fill(Min, Min + 100007, 1e11);
  Min[u] = 0;
  node nd;
  nd.id = u;
  nd.dp = 0;

  priority_queue<node> q;
  q.push(nd);

  while (q.size() > 0) {
    nd = q.top();
    q.pop();
    if (mark[nd.id])
      continue;
    mark[nd.id] = 1;
    int u = nd.id;

    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i].des;
      int val = adj[u][i].w;

      if (Min[v] <= val + nd.dp)
        continue;
      Min[v] = val + nd.dp;
      node nn;
      nn.id = v;
      nn.dp = val + nd.dp;
      q.push(nn);
    }
  }
}

int main() {
  int u;
  cin >> n >> m >> u;
  for (int i = 0; i < m; i++) {
    int x, y;
    edge e;
    cin >> x >> y >> e.w;
    e.des = y;
    adj[x].push_back(e);
  }
  prim(u);
  for (int i = 0; i < n; i++) {
    if (Min[i] < 1e11)
      cout << Min[i] << endl;
    else
      cout << "INF" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct node {
  int id;
  ll dp;
};

struct edge {
  int des;
  ll w;
};

int n, m;
vector<edge> adj[100007];
ll Min[100007];
bool mark[100007];

bool operator<(node a, node b) { return a.dp >= b.dp; }

void prim(int u) {
  fill(Min, Min + 100007, 1e11);
  Min[u] = 0;
  node nd;
  nd.id = u;
  nd.dp = 0;

  priority_queue<node> q;
  q.push(nd);

  while (q.size() > 0) {
    nd = q.top();
    q.pop();
    if (mark[nd.id])
      continue;
    mark[nd.id] = 1;
    int u = nd.id;

    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i].des;
      int val = adj[u][i].w;

      if (Min[v] <= val + nd.dp)
        continue;
      Min[v] = val + nd.dp;
      node nn;
      nn.id = v;
      nn.dp = val + nd.dp;
      q.push(nn);
    }
  }
}

int main() {
  int u;
  cin >> n >> m >> u;
  for (int i = 0; i < m; i++) {
    int x, y;
    edge e;
    cin >> x >> y >> e.w;
    e.des = y;
    adj[x].push_back(e);
  }
  prim(u);
  for (int i = 0; i < n; i++) {
    if (Min[i] < 1e11)
      cout << Min[i] << endl;
    else
      cout << "INF" << endl;
  }
}
Problem p02361 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <queue>
#include <vector>
#define INF 50000000000
struct vertex {
  std::vector<int> edge_to;
  std::vector<int> edge_cost;
  bool done;
  long long int mincost;
};
std::vector<vertex> G(10000);
void shortest_path(int v);
int V, E;
int r;
int main(void) {
  std::cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    int from, to, cost;
    std::cin >> from >> to >> cost;
    G[from].edge_to.push_back(to);
    G[from].edge_cost.push_back(cost);
    //		G[to].edge_to.push_back(from);
    //		G[to].edge_cost.push_back(cost);
  }
  shortest_path(r);
  for (int i = 0; i < V; i++) {
    if (G[i].mincost != INF) {
      std::cout << G[i].mincost << std::endl;
    } else {
      std::cout << "INF" << std::endl;
    }
  }
  return 0;
}
void shortest_path(int v) {
  for (int i = 0; i < V; i++) {
    G[i].mincost = INF;
  }
  G[v].mincost = 0;
  while (1) {
    bool update = false;
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < G[i].edge_to.size(); j++) {
        if (G[G[i].edge_to[j]].mincost > G[i].mincost + G[i].edge_cost[j]) {
          G[G[i].edge_to[j]].mincost = G[i].mincost + G[i].edge_cost[j];
          update = true;
        }
      }
    }
    if (!update) {
      break;
    }
  }
}

Fixed submission:
#include <iostream>
#include <queue>
#include <vector>
#define INF 50000000000
struct vertex {
  std::vector<int> edge_to;
  std::vector<int> edge_cost;
  bool done;
  long long int mincost;
};
std::vector<vertex> G(100000);
void shortest_path(int v);
int V, E;
int r;
int main(void) {
  std::cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    int from, to, cost;
    std::cin >> from >> to >> cost;
    G[from].edge_to.push_back(to);
    G[from].edge_cost.push_back(cost);
    //		G[to].edge_to.push_back(from);
    //		G[to].edge_cost.push_back(cost);
  }
  shortest_path(r);
  for (int i = 0; i < V; i++) {
    if (G[i].mincost != INF) {
      std::cout << G[i].mincost << std::endl;
    } else {
      std::cout << "INF" << std::endl;
    }
  }
  return 0;
}
void shortest_path(int v) {
  for (int i = 0; i < V; i++) {
    G[i].mincost = INF;
  }
  G[v].mincost = 0;
  while (1) {
    bool update = false;
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < G[i].edge_to.size(); j++) {
        if (G[G[i].edge_to[j]].mincost > G[i].mincost + G[i].edge_cost[j]) {
          G[G[i].edge_to[j]].mincost = G[i].mincost + G[i].edge_cost[j];
          update = true;
        }
      }
    }
    if (!update) {
      break;
    }
  }
}
Problem p02361 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
typedef pair<int, int> P;
int V, E, r;
int d[100000];
vector<P> edges[10000];
priority_queue<P, vector<P>, greater<P>> q;

void solve() {
  P start = P(0, r);
  d[r] = 0;
  q.push(start);

  while (!q.empty()) {
    P p = q.top();
    q.pop();
    if (d[p.second] < p.first)
      continue;

    for (int i = 0; i < edges[p.second].size(); i++) {
      P edge = edges[p.second][i];
      P next = P(p.first + edge.second, edge.first);
      if (d[next.second] < next.first)
        continue;

      d[next.second] = next.first;
      q.push(next);
    }
  }

  return;
}

int main() {
  fill_n(d, 100000, inf);
  cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    int A, B, cost;
    cin >> A >> B >> cost;
    edges[A].push_back(P(B, cost));
  }

  solve();
  for (int i = 0; i < V; i++) {
    if (d[i] == inf) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
typedef pair<int, int> P;
int V, E, r;
int d[100000];
vector<P> edges[100000];
priority_queue<P, vector<P>, greater<P>> q;

void solve() {
  P start = P(0, r);
  d[r] = 0;
  q.push(start);

  while (!q.empty()) {
    P p = q.top();
    q.pop();
    if (d[p.second] < p.first)
      continue;

    for (int i = 0; i < edges[p.second].size(); i++) {
      P edge = edges[p.second][i];
      P next = P(p.first + edge.second, edge.first);
      if (d[next.second] < next.first)
        continue;

      d[next.second] = next.first;
      q.push(next);
    }
  }

  return;
}

int main() {
  fill_n(d, 100000, inf);
  cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    int A, B, cost;
    cin >> A >> B >> cost;
    edges[A].push_back(P(B, cost));
  }

  solve();
  for (int i = 0; i < V; i++) {
    if (d[i] == inf) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
}
Problem p02361 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <queue>
#define ll long long
#define INF 100000000000000
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  ll V, E, r;
  cin >> V >> E >> r;
  vector<vector<pair<ll, ll>>> edges(V);
  vector<ll> dist(V, INF);
  for (ll i = 0; i < E; i++) {
    ll s, t, d;
    cin >> s >> t >> d;
    edges[s].push_back(make_pair(t, d));
  }
  dist[r] = 0;
  priority_queue<pair<ll, ll>> pq;
  pq.push(make_pair(0, r));
  while (!pq.empty()) {
    ll source = pq.top().second;
    pq.pop();
    for (auto i : edges[source]) {
      if (dist[i.first] == INF || dist[source] + i.second < dist[i.first]) {
        dist[i.first] = dist[source] + i.second;
        pq.push(make_pair(dist[i.first], i.first));
      }
    }
  }
  for (ll i = 0; i < V; i++) {
    if (dist[i] == INF)
      cout << "INF" << endl;
    else
      cout << dist[i] << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#define ll long long
#define INF 100000000000000
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  ll V, E, r;
  cin >> V >> E >> r;
  vector<vector<pair<ll, ll>>> edges(V);
  vector<ll> dist(V, INF);
  for (ll i = 0; i < E; i++) {
    ll s, t, d;
    cin >> s >> t >> d;
    edges[s].push_back(make_pair(t, d));
  }
  dist[r] = 0;
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
  pq.push(make_pair(0, r));
  while (!pq.empty()) {
    ll source = pq.top().second;
    pq.pop();
    for (auto i : edges[source]) {
      if (dist[i.first] == INF || dist[source] + i.second < dist[i.first]) {
        dist[i.first] = dist[source] + i.second;
        pq.push(make_pair(dist[i.first], i.first));
      }
    }
  }
  for (ll i = 0; i < V; i++) {
    if (dist[i] == INF)
      cout << "INF" << endl;
    else
      cout << dist[i] << endl;
  }
}
Problem p02361 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define INF 10000000000000000
#define ll long long

using namespace std;

int main() {
  ll V, E, r;
  cin >> V >> E >> r;
  vector<vector<pair<ll, ll>>> edges(V);
  for (ll i = 0; i < E; i++) {
    ll s, t, d;
    cin >> s >> t >> d;
    edges[s].push_back(make_pair(t, d));
  }
  vector<ll> dist(V, INF);
  dist[r] = 0;
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, less<pair<ll, ll>>> pq;
  pq.push(make_pair(0, r));

  while (!pq.empty()) {
    ll source = pq.top().second;
    pq.pop();
    for (pair<ll, ll> edge : edges[source]) {
      if (dist[edge.first] > dist[source] + edge.second) {
        dist[edge.first] = dist[source] + edge.second;
        pq.push(make_pair(dist[edge.first], edge.first));
      }
    }
  }

  for (ll i = 0; i < V; i++) {
    if (dist[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << dist[i] << endl;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define INF 10000000000000000
#define ll long long

using namespace std;

int main() {
  ll V, E, r;
  cin >> V >> E >> r;
  vector<vector<pair<ll, ll>>> edges(V);
  for (ll i = 0; i < E; i++) {
    ll s, t, d;
    cin >> s >> t >> d;
    edges[s].push_back(make_pair(t, d));
  }
  vector<ll> dist(V, INF);
  dist[r] = 0;
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
  pq.push(make_pair(0, r));

  while (!pq.empty()) {
    ll source = pq.top().second;
    pq.pop();
    for (pair<ll, ll> edge : edges[source]) {
      if (dist[edge.first] > dist[source] + edge.second) {
        dist[edge.first] = dist[source] + edge.second;
        pq.push(make_pair(dist[edge.first], edge.first));
      }
    }
  }

  for (ll i = 0; i < V; i++) {
    if (dist[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << dist[i] << endl;
    }
  }
}
Problem p02361 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, j) for (int i = 0; i < (int)(j); i++)
constexpr int INF = 1 << 28;
struct Edge {
  int to;
  ll cost;
  Edge(int to, ll cost) : to(to), cost(cost) {}
};
using EdgeList = vector<vector<Edge>>;
using Vatex = int;
constexpr ll INFL = 1LL << 60;
struct State {
  int index;
  ll cost;
  State(int i, ll c) : index(i), cost(c) {}
  bool operator>(const State &r) const { return cost < r.cost; }
};
//
//
vector<ll> dijkstra(const EdgeList &G, int start) {
  priority_queue<State, vector<State>, greater<State>> que;
  vector<ll> dist(G.size(), INFL);
  que.emplace(start, 0);
  dist[start] = 0;
  while (not que.empty()) {
    State now = que.top();
    que.pop();
    for (Edge e : G[now.index]) {
      if (dist[e.to] > now.cost + e.cost) {
        State nxt = State(e.to, now.cost + e.cost);
        dist[e.to] = nxt.cost;
        que.push(nxt);
      }
    }
  }
  return dist;
}
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
int main() {
  int N, M, R;
  cin >> N >> M >> R;
  EdgeList E(N);
  rep(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    E[a].push_back(Edge(b, c));
  }
  auto dist = dijkstra(E, R);
  for (ll d : dist)
    cout << (d < INFL ? to_string(d) : "INF") << endl;
  return 0;
}

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, j) for (int i = 0; i < (int)(j); i++)
constexpr int INF = 1 << 28;
struct Edge {
  int to;
  ll cost;
  Edge(int to, ll cost) : to(to), cost(cost) {}
};
using EdgeList = vector<vector<Edge>>;
using Vatex = int;
constexpr ll INFL = 1LL << 60;
struct State {
  int index;
  ll cost;
  State(int i, ll c) : index(i), cost(c) {}
  bool operator>(const State &r) const { return cost > r.cost; }
};
//
//
vector<ll> dijkstra(const EdgeList &G, int start) {
  priority_queue<State, vector<State>, greater<State>> que;
  vector<ll> dist(G.size(), INFL);
  que.emplace(start, 0);
  dist[start] = 0;
  while (not que.empty()) {
    State now = que.top();
    que.pop();
    for (Edge e : G[now.index]) {
      if (dist[e.to] > now.cost + e.cost) {
        State nxt = State(e.to, now.cost + e.cost);
        dist[e.to] = nxt.cost;
        que.push(nxt);
      }
    }
  }
  return dist;
}
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
int main() {
  int N, M, R;
  cin >> N >> M >> R;
  EdgeList E(N);
  rep(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    E[a].push_back(Edge(b, c));
  }
  auto dist = dijkstra(E, R);
  for (ll d : dist)
    cout << (d < INFL ? to_string(d) : "INF") << endl;
  return 0;
}
Problem p02361 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long LL;
int V, E, S;
LL d[100001];
typedef pair<LL, int> P;
vector<P> G[100001];
int main() {
  cin >> V >> E >> S;
  REP(i, E) {
    int a, b;
    LL c;
    cin >> a >> b >> c;
    G[a].push_back(make_pair(c, b));
    // G[b].push_back(make_pair(c,a));
  }
  REP(i, 100001) { d[i] = 10e12; }
  priority_queue<P> q;
  q.push(make_pair(0, S));
  while (!q.empty()) {
    P p = q.top();
    q.pop();
    LL cost = p.first;
    LL num = p.second;
    if (d[num] < cost)
      continue;
    // cout<<num<<"aaa"<<cost<<endl;
    d[num] = cost;
    REP(i, G[num].size()) {
      if (d[num] + G[num][i].first < d[G[num][i].second]) {
        q.push(make_pair(d[num] + G[num][i].first, G[num][i].second));
        d[G[num][i].second] = d[num] + G[num][i].first;
      }
    }
  }
  REP(i, V) {
    if (d[i] == 10e12) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
  return (0);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long LL;
int V, E, S;
LL d[100001];
typedef pair<LL, int> P;
vector<P> G[100001];
int main() {
  cin >> V >> E >> S;
  REP(i, E) {
    int a, b;
    LL c;
    cin >> a >> b >> c;
    G[a].push_back(make_pair(c, b));
    // G[b].push_back(make_pair(c,a));
  }
  REP(i, 100001) { d[i] = 10e12; }
  priority_queue<P, vector<P>, greater<P>> q;
  q.push(make_pair(0, S));
  while (!q.empty()) {
    P p = q.top();
    q.pop();
    LL cost = p.first;
    LL num = p.second;
    if (d[num] < cost)
      continue;
    // cout<<num<<"aaa"<<cost<<endl;
    d[num] = cost;
    REP(i, G[num].size()) {
      if (d[num] + G[num][i].first < d[G[num][i].second]) {
        q.push(make_pair(d[num] + G[num][i].first, G[num][i].second));
        d[G[num][i].second] = d[num] + G[num][i].first;
      }
    }
  }
  REP(i, V) {
    if (d[i] == 10e12) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
  return (0);
}
Problem p02361 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <numeric>

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

#define numof(array) (sizeof(array) / sizeof *(array))

const int INF = 1000000007;
const int MAX_V = 10000007;

typedef long long ll;
typedef pair<int, int> P; // first: ???????????¢???second: ???????????????

struct edge {
  int to;
  int cost;
};

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

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> qu;
  fill(d, d + V, INF);
  d[s] = 0;
  qu.push(P(0, s));
  while (!qu.empty()) {
    P p = qu.top();
    qu.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;
        qu.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {

  int E, r;
  cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    edge e = {t, d};
    //    e.to = t; e.cost = d;
    G[s].push_back(e);
  }
  dijkstra(r);
  for (int i = 0; i < V; i++) {
    if (d[i] == INF)
      cout << "INF" << endl;
    else
      cout << d[i] << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>

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

#define numof(array) (sizeof(array) / sizeof *(array))

const int INF = 1000000007;
const int MAX_V = 1000007;

typedef long long ll;
typedef pair<int, int> P; // first: ???????????¢???second: ???????????????

struct edge {
  int to;
  int cost;
};

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

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> qu;
  fill(d, d + V, INF);
  d[s] = 0;
  qu.push(P(0, s));
  while (!qu.empty()) {
    P p = qu.top();
    qu.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;
        qu.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {

  int E, r;
  cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    edge e = {t, d};
    //    e.to = t; e.cost = d;
    G[s].push_back(e);
  }
  dijkstra(r);
  for (int i = 0; i < V; i++) {
    if (d[i] == INF)
      cout << "INF" << endl;
    else
      cout << d[i] << endl;
  }

  return 0;
}