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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
const int INF = 2147483647;
const int maxn = 100000;
const int maxm = 500000;
int n, m, s;
int fir[maxn], nxt[maxm], to[maxm], val[maxm], cnt;
void add_edge(int u, int v, int w) {
  nxt[++cnt] = fir[u];
  fir[u] = cnt;
  to[cnt] = v;
  val[cnt] = w;
}
int dis[maxn], inq[maxn];
void SPFA(int s) {
  for (int i = 0; i < n; i++)
    dis[i] = INF;
  dis[s] = 0;
  queue<int> Q;
  Q.push(s);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int e = fir[u]; e; e = nxt[e]) {
      int v = to[e], w = val[e];
      if (dis[u] + w < dis[v]) {
        dis[v] = dis[u] + w;
        if (!inq[v])
          Q.push(v);
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int u, v, w, i = 0; i < m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    add_edge(u, v, w);
  }
  SPFA(s);
  for (int i = 0; i < n; i++) {
    if (dis[i] == INF) {
      printf("INF\\n");
    } else {
      printf("%d\\n", dis[i]);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int INF = 2147483647;
const int maxn = 100000;
const int maxm = 500000;
int n, m, s;
int fir[maxn], nxt[maxm], to[maxm], val[maxm], cnt;
void add_edge(int u, int v, int w) {
  nxt[++cnt] = fir[u];
  fir[u] = cnt;
  to[cnt] = v;
  val[cnt] = w;
}
int dis[maxn], vis[maxn]; // vis[i]???i??????????¢??????????
void Dijkstra(int s) {
  for (int i = 0; i < n; i++)
    dis[i] = INF;
  dis[s] = 0;
  for (int i = 0; i < n; i++) {
    int pos, mn = INF;
    for (int j = 0; j < n; j++)
      if (!vis[j] && dis[j] < mn)
        mn = dis[pos = j]; //??´??°?????°??????dis
    vis[pos] = 1;
    for (int e = fir[pos]; e; e = nxt[e]) {
      int v = to[e], w = val[e];
      if (!vis[v] && mn + w < dis[v])
        dis[v] = mn + w;
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int u, v, w, i = 0; i < m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    add_edge(u, v, w);
  }
  Dijkstra(s);
  for (int i = 0; i < n; i++) {
    if (dis[i] == INF) {
      printf("INF\\n");
    } else {
      printf("%d\\n", dis[i]);
    }
  }
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>

using namespace std;

const int Inf = 10000 * 100000 + 100;
int V, E, R, S, T[500000 + 10], D[500000 + 10], H[500000 + 10], N[500000 + 10];
int C[100000 + 10], P[100000 + 10];

int main() {
  queue<int> Q;
  cin >> V >> E >> R;
  for (int i = 1; i <= E; i++) {
    cin >> S >> T[i] >> D[i];
    N[i] = H[S];
    H[S] = i;
  }
  fill(C, C + 100010, Inf);
  C[R] = 0;
  Q.push(R);
  P[R] = 1;
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    P[u] = 0;
    for (int i = H[u]; i; i = N[i]) {
      int t = T[i];
      if (C[t] > C[u] + D[i]) {
        C[t] = C[u] + D[i];
        if (!P[t]) {
          Q.push(t);
          P[t] = 1;
        }
      }
    }
  }

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

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

const int Inf = 10000 * 100000 + 100;
int V, E, R, S[500000 + 10], T[500000 + 10], D[50000 + 10];
int C[100000 + 10];

int main() {
  cin >> V >> E >> R;
  for (int i = 0; i < E; i++) {
    cin >> S[i] >> T[i] >> D[i];
  }
  fill(C, C + 100010, Inf);
  C[R] = 0;
  for (int i = 0; i < V; i++) {
    bool update = false;
    for (int j = 0; j < E; j++) {
      int s = S[j], t = T[j], d = D[j];
      if (C[s] < Inf) {
        C[t] = C[t] > (C[s] + d) ? C[s] + d : C[t];
        update = true;
      }
    }
    if (!update)
      break;
  }

  for (int i = 0; i < V; i++) {
    if (C[i] < Inf) {
      cout << C[i] << endl;
    } else {
      cout << "INF" << endl;
    }
  }
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
#define INF 2147483647

struct edge {
  int to, cost;
};
int V, E;

vector<edge> G[100010];

multimap<int, int> l;

ll d[500010];

void dijkstra(int s) {
  fill(d, d + V, INF);
  d[s] = 0;

  l.insert(make_pair(0, s));

  while (l.size() > 0) {
    int p = l.begin()->first;
    int v = l.begin()->second;
    l.erase(l.begin());

    if (d[v] < p)
      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;
        l.insert(make_pair(d[e.to], e.to));
      }
    }
  }
}

int main() {

  int r;
  cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    edge e;
    int from;
    cin >> from >> e.to >> e.cost;
    G[from].push_back(e);
  }

  dijkstra(r);

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

Error: TLE

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, num, 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) {
  if (a.first == b.first)
    return a.second > b.second;
  return a.first > b.first;
}

int main() {
  cin >> V >> E >> R;
  // store data like SPFA
  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);
  num = 1;
  Ans[R] = 0;
  Q.push(make_pair(0, R));

  while (!Q.empty()) {
    a = Q.top().first;
    b = Q.top().second;
    Q.pop();
    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, verdict: 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>, 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;
    }
  }
}

Error: TLE

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>> 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;
    }
  }
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int inf = 1000000000;

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

struct Dist {
  int to, from, dist;
};

int main() {
  int n, m, r;
  cin >> n >> m >> r;
  vector<int> v(n, inf);
  vector<Dist> c(m);
  for (int i = 0; i < m; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    c[i].to = t;
    c[i].from = s;
    c[i].dist = d;
  }

  v[r] = 0;

  while (true) {
    bool f = false;
    for (int i = 0; i < c.size(); i++) {
      Dist d = c[i];
      if (v[d.from] != inf && v[d.to] > v[d.from] + d.dist) {
        v[d.to] = v[d.from] + d.dist;
        f = true;
      }
    }
    if (!f)
      break;
  }

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

  return 0;
}

// EOF

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int inf = 1000000000;

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

struct Dist {
  int to, from, dist;
};

int main() {
  int n, m, r;
  cin >> n >> m >> r;
  vector<int> v(n, inf);
  vector<Dist> c(m);
  for (int i = 0; i < m; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    c[i].to = t;
    c[i].from = s;
    c[i].dist = d;
  }

  v[r] = 0;
  vector<int> visited(n, inf);
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  q.push(make_pair(0, r));
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int d = p.first;
    int pos = p.second;
    visited[pos] = d;
    v[pos] = min(v[pos], d);

    for (int i = 0; i < c.size(); i++) {
      if (c[i].from == pos && visited[c[i].to] > d + c[i].dist) {
        q.push(make_pair(d + c[i].dist, c[i].to));
      }
    }
  }

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

  return 0;
}

// EOF
Problem p02361 (C++) — buggy submission, verdict: 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[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;
    }
  }
}

Error: 0

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[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;
    }
  }
}
Problem p02361 (C++) — buggy submission, verdict: 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(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;
    }
  }
}

Error: 0

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(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;
    }
  }
}
Problem p02361 (C++) — buggy submission, verdict: 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[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;
  }
}

Error: 0

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[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;
  }
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;
#define MV 100000
#define INF 1e9

struct edge {
  int to, cost;
};
vector<edge> G[MV];
bool used[MV];
int V, E;
int d[MV + 1];

void bellmanford(int s) {
  fill(d, d + MV, INF);
  d[s] = 0;
  int c = 0;
  bool upd = false;
  while (true) {
    upd = false;
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < G[i].size(); j++) {
        edge e = G[i][j];
        if (d[i] != INF && d[e.to] > d[i] + e.cost) {
          d[e.to] = d[i] + e.cost;
          upd = true;
        }
      }
    }
    if (!upd)
      break;
    if (c == V - 1)
      return;
    c++;
  }
}

int main() {
  d[MV] = INF + 10;
  int first;

  cin >> V >> E >> first;
  for (int i = 0; i < E; i++) {
    int f, t;
    edge e;
    cin >> f >> e.to >> e.cost;
    G[f].push_back(e);
    t = e.to;

    // e.to = f;
    // G[t].push_back(e);
  }

  bellmanford(first);

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

Error: TLE

Fixed submission:

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

using namespace std;
#define MV 100000
#define INF 1e9

struct edge {
  int to, cost;
};
vector<edge> G[MV];
bool used[MV];
int d[MV + 1];

int V, E;

void dijkstra(int first) {
  fill(d, d + MV, INF);
  fill(used, used + MV, false);
  d[first] = 0;

  for (int i = 0; i < V; i++) {
    int now = MV;

    for (int j = 0; j < V; j++) {
      if (used[j] == false && d[now] > d[j]) {
        now = j;
      }
    }
    // cout << now << endl;
    used[now] = true;
    for (int j = 0; j < G[now].size(); j++) {
      edge e = G[now][j];
      d[e.to] = min(d[e.to], d[now] + e.cost);
    }
    /*for(int j = 0;j < V;j++)
      cout << d[j] << "   ";
      cout << endl;*/
  }
}

int main() {
  d[MV] = INF + 10;
  int first;

  cin >> V >> E >> first;
  for (int i = 0; i < E; i++) {
    int f, t;
    edge e;
    cin >> f >> e.to >> e.cost;
    G[f].push_back(e);
    t = e.to;
    /*e.to = f;
      G[t].push_back(e);*/
  }

  dijkstra(first);

  for (int i = 0; i < V; i++) {
    if (d[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
}
Problem p02361 (C++) — buggy submission, verdict: 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[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;
  }
}

Error: 0

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[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;
  }
}