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

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int V, E, R, S[500010], T[500010], D[500010];
int C[100010];
const int Inf = 10000 * 100000 + 100;

int main() {
  cin >> V >> E >> R;
  for (int i = 0; i < E; i++) {
    cin >> S[i] >> T[i] >> D[i];
  }
  for (int i = 0; i < V; i++) {
    C[i] = 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[s] + d) {
        C[t] = C[s] + d;
        update = true;
      }
    }
    if (!update)
      break;
  }
  for (int i = 0; i < V; i++) {
    if (C[i] == Inf)
      cout << "INF" << endl;
    else
      cout << C[i] << endl;
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;
int main() {
  int co[100000][100000];
  int inf = 100000 * 10000;
  int n, m, a, b, ab, st;
  scanf("%d,%d,%d", &n, &m, &st);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        co[i][j] = 0;
      else
        co[i][j] = inf;
    }
  }
  for (int i = 0; i < m; i++) {
    scanf("%d,%d,%d", &a, &b, &ab);
    co[a][b] = ab;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (co[k][j] > co[k][i] + co[i][j])
          co[k][j] = co[k][i] + co[i][j];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (co[st][i] >= inf) {
      cout << "INF" << endl;
    } else
      cout << co[st][i] << endl;
  }
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

#define INF 1000000000
typedef pair<int, int> P;
int v, e, r;
int s[1000000], t[1000000], d[10000000];
vector<P> vec[500000];

void dijkstra() {
  priority_queue<P, vector<P>, greater<P>> pq;
  pq.push(P(0, r));
  int res[v];
  fill(res, res + v, INF);
  res[r] = 0;

  while (!pq.empty()) {
    P tmp = pq.top();
    pq.pop();
    if (tmp.first > res[tmp.second])
      continue;
    for (int i = 0; i < vec[tmp.second].size(); i++) {
      if (res[vec[tmp.second][i].first] >
          res[tmp.second] + vec[tmp.second][i].second) {
        res[vec[tmp.second][i].first] =
            res[tmp.second] + vec[tmp.second][i].second;
        pq.push(P(res[vec[tmp.second][i].first], vec[tmp.second][i].first));
      }
    }
  }
  for (int i = 0; i < v; i++) {
    if (res[i] == INF)
      printf("INF\\n");
    else
      printf("%d\\n", res[i]);
  }
}

int main() {
  scanf("%d%d%d", &v, &e, &r);
  for (int i = 0; i < e; i++) {
    scanf("%d%d%d", &s[i], &t[i], &d[i]);
    vec[s[i]].push_back(P(t[i], d[i]));
  }

  /*  for(int i=0;i<e;i++){
      s[i+e]=t[i];
      t[i+e]=s[i];
      d[i+e]=d[i];
    }
  */
  dijkstra();

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

#define INF 100000000
typedef pair<int, int> P;
int v, e, r;
int s[1000000], t[1000000], d[10000000];

void dijkstra() {
  priority_queue<P, vector<P>, greater<P>> pq;
  pq.push(P(0, r));
  int res[v];
  fill(res, res + v, INF);
  res[r] = 0;

  while (!pq.empty()) {
    P tmp = pq.top();
    pq.pop();
    if (tmp.first > res[tmp.second])
      continue;
    for (int i = 0; i < e; i++) {
      if (tmp.second == s[i]) {
        if (res[t[i]] > res[s[i]] + d[i]) {
          res[t[i]] = res[s[i]] + d[i];
          pq.push(P(res[t[i]], t[i]));
        }
      }
    }
  }
  for (int i = 0; i < v; i++) {
    if (res[i] == INF)
      printf("INF\\n");
    else
      printf("%d\\n", res[i]);
  }
}

int main() {
  scanf("%d%d%d", &v, &e, &r);
  for (int i = 0; i < e; i++) {
    scanf("%d%d%d", &s[i], &t[i], &d[i]);
  }

  /*  for(int i=0;i<e;i++){
      s[i+e]=t[i];
      t[i+e]=s[i];
      d[i+e]=d[i];
    }
  */
  dijkstra();

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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
#define INF 1000000000

using namespace std;

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

int v, e, r;
int s[500003], t[500003], c[500003];
int d[100003];
vector<edge> G[500003];

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

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

int main() {
  scanf("%d%d%d", &v, &e, &r);
  for (int i = 0; i < e; i++) {
    scanf("%d%d%d", &s[i], &t[i], &c[i]);
    edge tmp = {t[i], c[i]};
    G[s[i]].push_back(tmp);
  }

  dijkstra(r);

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
#define INF 10000000

using namespace std;

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

int v, e, r;
int s[500003], t[500003], c[500003];
int d[100003];
vector<edge> G[500003];

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

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

void init() {
  for (int i = 0; i < v; i++) {
    for (int j = 0; j < e; j++) {
      if (s[j] == i) {
        edge tmp = {t[j], c[j]};
        G[i].push_back(tmp);
      }
    }
  }
}

int main() {
  scanf("%d%d%d", &v, &e, &r);
  for (int i = 0; i < e; i++)
    scanf("%d%d%d", &s[i], &t[i], &c[i]);

  init();

  dijkstra(r);

  for (int i = 0; i < v; i++) {
    if (d[i] == INF)
      printf("INF\\n");
    else
      printf("%d\\n", d[i]);
  }
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define TEISU 1000000
#define INF 1145141919810LL
#define BLACK 2
#define GRAY 1
#define WHITE 0
#define MAX_N 500000

long long d[MAX_N];
long long color[MAX_N];
vector<long long> x[MAX_N];

priority_queue<long long, vector<long long>, greater<long long>> Q;

void dijkstra() {
  while (!Q.empty()) {
    long long A = Q.top() / TEISU;
    long long B = Q.top() % TEISU;
    Q.pop();
    color[B] = BLACK;

    if (d[B] < A * (-1))
      continue;

    for (int v = 0; v < x[B].size(); v++) {
      int w = x[B][v] / TEISU;

      if (color[w] == BLACK)
        continue;

      if (d[w] > d[B] + x[B][v] % TEISU) {

        d[w] = d[B] + x[B][v] % TEISU;
        Q.push(d[w] * TEISU + w);
        color[w] = GRAY;
      }
    }
  }
}

int main() {
  long long n, m, r, a, b, c;
  cin >> n >> m >> r;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c;
    x[a].push_back(b * TEISU + c);
  }
  Q.push(r);
  for (int i = 0; i < MAX_N; i++) {
    color[i] = WHITE;
    d[i] = INF;
  }
  d[r] = 0;
  color[r] = GRAY;
  dijkstra();
  for (int i = 0; i < n; i++) {
    if (d[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int V, E;
vector<long long> x[200000];
long long y[200000], a, b, c, d, cnt, loop;
int t[200000];
bool u[200000];

priority_queue<long long, vector<long long>, greater<long long>> Q;

void dijkstra(int p, int s, vector<long long> k[]) {
  int g = 5000;
  memset(y, 127, sizeof(y));
  Q.push(s);
  y[s] = 0;
  while (!Q.empty()) {
    a = Q.top() / 1000000;
    b = Q.top() % 1000000;
    t[b] += 2000000;
    for (int i = 0; i < k[b].size(); i++) {
      c = k[b][i] / 1000000;
      d = k[b][i] % 1000000;
      t[d]++;
      if (t[d] < g) {
        y[d] = min(y[d], y[b] + c);
        Q.push(y[d] * 1000000 + d);
        loop++;
        if (loop >= 70000000) {
          return;
        }
      }
    }
    Q.pop();
  }
}

int e, f, g, h;

int main() {
  cin >> V >> E;
  cin >> h;
  for (int i = 0; i < E; i++) {
    cin >> e >> f >> g;
    x[e].push_back(g * 1000000 + f);
  }
  dijkstra(V, h, x);
  for (int i = 0; i < V; i++) {
    if (y[i] < 100000000) {
      cout << y[i] << endl;
    } else {
      cout << "INF" << endl;
    }
  }
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Runtime Error

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

Error: 0

Fixed submission:

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

// ?????????single source shortest path
// Bellman-Ford
#include <iostream>
#define INF 1001001000
#define BIG 500100
#define rep(i, p) for (int i = 0; i < p; i++)
#define rep1(i, p) for (int i = 1; i <= p; i++)
#define pb push_back
using namespace std;
int V, E, r, s, t, w;
int S[BIG];
int T[BIG];
int W[BIG];
int D[BIG];
int main() {
  // init
  rep(i, BIG) D[i] = INF;
  // r is source of graph
  cin >> V >> E >> r;
  rep(i, E) {
    cin >> s >> t >> w;
    S[i] = s;
    T[i] = t;
    W[i] = w;
  }
  D[r] = 0;
  rep(i, V) {
    bool update = false;
    rep(j, E) {
      // s,t ??? edge j ??? vartex
      s = S[j];
      t = T[j];
      w = W[j];
      if (D[t] > D[s] + w) {
        D[t] = D[s] + w;
        update = true;
      }
    }
    if (!update)
      break;
  }
  rep(i, V) {
    if (D[i] == INF)
      cout << "INF" << endl;
    else
      cout << D[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

// ?????????single source shortest path
// Bellman-Ford
#include <iostream>
#define INF 100100100
#define BIG 500100
#define rep(i, p) for (int i = 0; i < p; i++)
#define rep1(i, p) for (int i = 1; i <= p; i++)
#define pb push_back
using namespace std;
int V, E, r, s, t, w;
int S[BIG];
int T[BIG];
int W[BIG];
int D[BIG];
int main() {
  // init
  rep(i, BIG) D[i] = INF;
  // r is source of graph
  cin >> V >> E >> r;
  rep(i, E) {
    cin >> s >> t >> w;
    S[i] = s;
    T[i] = t;
    W[i] = w;
  }
  D[r] = 0;
  rep(i, V) {
    bool update = false;
    rep(j, E) {
      // s,t ??? edge j ??? vartex
      s = S[j];
      t = T[j];
      w = W[j];
      if (D[t] >= D[s] + w) {
        D[t] = D[s] + w;
        update = true;
      }
    }
    if (!update)
      break;
  }
  rep(i, V) {
    if (D[i] == INF)
      cout << "INF" << endl;
    else
      cout << D[i] << endl;
  }
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "limits.h"
#include <cstring>
#include <iostream>
using namespace std;
#define Maxvernum 100000
#define Maxarcnum 500000
typedef struct arcs {
  int start;
  int to;
  int cost;
};
arcs input[Maxarcnum];
int dist[Maxvernum];
int visited[Maxvernum];
int V, E, r;
void BellmanFord(int r) {
  while (1) {
    int flag = 0;
    for (int i = 0; i < E; i++) {
      if (dist[input[i].start] != INT_MAX &&
          dist[input[i].start] + input[i].cost < dist[input[i].to]) {
        dist[input[i].to] = dist[input[i].start] + input[i].cost;
        flag = 1;
      }
    }
    if (flag == 0)
      break;
  }
}
int main() {
  cin >> V >> E >> r;
  for (int i = 0; i < Maxvernum; i++)
    dist[i] = INT_MAX;
  memset(visited, 0, sizeof(visited));
  for (int i = 0; i < E; i++) {
    cin >> input[i].start >> input[i].to >> input[i].cost;
    if (input[i].start == r)
      dist[input[i].to] = input[i].cost;
  }
  dist[r] = 0;
  visited[r] = 1;
  BellmanFord(r);
  for (int i = 0; i < V; i++)
    if (dist[i] != INT_MAX)
      cout << dist[i] << endl;
    else
      cout << "INF" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include "limits.h"
#include <cstring>
#include <iostream>
using namespace std;
#define Maxvernum 100000
#define Maxarcnum 500000
typedef struct arcs {
  int start;
  int to;
  int cost;
};
arcs input[Maxarcnum];
int dist[Maxvernum];
int visited[Maxvernum];
int V, E, r;
void Dijkstra(int r) {
  for (int i = 1; i < V; i++) {
    int min = INT_MAX;
    int ver = 0;
    int count = 0;
    for (int j = 0; j < V; j++) {
      if (visited[j] == 0 && dist[j] < min) {
        min = dist[j];
        ver = j;
        count++;
      }
    }
    if (count == 0)
      break;
    visited[ver] = 1;
    for (int i = 0; i < E; i++)
      if (input[i].start == ver && visited[input[i].to] == 0 &&
          min + input[i].cost < dist[input[i].to])
        dist[input[i].to] = min + input[i].cost;
  }
}
int main() {
  cin >> V >> E >> r;
  for (int i = 0; i < Maxvernum; i++)
    dist[i] = INT_MAX;
  memset(visited, 0, sizeof(visited));
  for (int i = 0; i < E; i++) {
    cin >> input[i].start >> input[i].to >> input[i].cost;
    if (input[i].start == r)
      dist[input[i].to] = input[i].cost;
  }
  dist[r] = 0;
  visited[r] = 1;
  Dijkstra(r);
  for (int i = 0; i < V; i++)
    if (dist[i] != INT_MAX)
      cout << dist[i] << endl;
    else
      cout << "INF" << endl;
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <queue>
#define MAX_VERTICE_NUM 100001
#define INF 2147483647
using namespace std;

typedef pair<int, int> pii;

int V, E, r, si, ti, di;
int d[MAX_VERTICE_NUM];
int S[MAX_VERTICE_NUM];
vector<vector<pii>> graph;
priority_queue<pii, vector<pii>, greater<pii>> q;

void init() {
  cin >> V >> E >> r;
  graph.resize(V);

  for (int i = 0; i < V; ++i) {
    S[i] = 0;
    d[i] = i == r ? 0 : INF;
  }
  for (int i = 0; i < E; ++i) {
    cin >> si >> ti >> di;
    graph[si].push_back(make_pair(di, ti));
  }
  q.push(make_pair(d[r], r));
}

void dijkstra() {
  while (!q.empty()) {
    pii tmp = q.top();
    q.pop();
    int x = tmp.second;
    if (S[x]) {
      continue;
    }
    S[x] = 1;
    for (int i = 0; i < graph[x].size(); ++i) {
      if (d[x] + graph[x][i].first < d[graph[x][i].second]) {
        d[graph[x][i].second] = d[x] + graph[x][i].first;
        q.push(make_pair(d[graph[x][i].second], graph[x][i].second));
      }
    }
  }
}

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

int main() {
  // freopen("in14.txt", "r", stdin);

  init();
  dijkstra();
  opAns();
}

Error: MLE

Fixed submission:

#include <iostream>
#include <queue>
#define MAX_VERTICE_NUM 100001
#define INF 10001
using namespace std;

typedef pair<int, int> pii;

int V, E, r, si, ti, di;
int d[MAX_VERTICE_NUM];
int S[MAX_VERTICE_NUM];
vector<vector<int>> graph;
priority_queue<pii, vector<pii>, greater<pii>> q;

void init() {
  cin >> V >> E >> r;
  graph.resize(V + 1);

  for (int i = 0; i < V; ++i) {
    graph[i] = vector<int>(MAX_VERTICE_NUM, INF);
    S[i] = 0;
    d[i] = i == r ? 0 : INF;
  }

  for (int i = 0; i < E; ++i) {
    cin >> si >> ti >> di;
    graph[si][ti] = di;
  }
  q.push(make_pair(d[r], r));
}

void dijkstra() {
  while (!q.empty()) {
    pii tmp = q.top();
    q.pop();
    int x = tmp.second;
    if (S[x]) {
      continue;
    }
    S[x] = 1;

    for (int i = 0; i < graph[x].size(); ++i) {
      if (d[x] + graph[x][i] < d[i]) {
        d[i] = d[x] + graph[x][i];
        q.push(make_pair(d[i], i));
      }
    }
  }
}

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

int main() {
  //    freopen("in14.txt", "r", stdin);

  init();
  dijkstra();
  opAns();
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>
#include <vector>

typedef std::uint_least64_t cost_t;
#define COST_INF UINT_LEAST64_MAX

struct Edge {
  int target;
  int distance;
};

struct Node {
  std::vector<Edge> edges;
  cost_t cost;

  Node() : cost(COST_INF) {}
};

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

  std::vector<Node> nodes(v);
  nodes[r].cost = 0;

  for (int i = 0; i < e; i++) {
    int s, t, d;
    std::cin >> s >> t >> d;
    nodes[s].edges.push_back({t, d});
  }

  auto greater_node = [&](int x, int y) {
    return nodes[x].cost > nodes[y].cost;
  };
  std::priority_queue<int, std::vector<int>, decltype(greater_node)> queue(
      greater_node);
  queue.push(r);

  while (!queue.empty()) {
    Node &node = nodes[queue.top()];
    queue.pop();

    for (Edge e : node.edges) {
      Node &target = nodes[e.target];
      cost_t new_cost = node.cost + e.distance;
      if (new_cost < target.cost) {
        target.cost = new_cost;
        queue.push(e.target);
      }
    }
  }

  for (Node &node : nodes) {
    if (node.cost == COST_INF)
      std::cout << "INF";
    else
      std::cout << node.cost;
    std::cout << std::endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <queue>
#include <sstream>
#include <string>
#include <vector>

typedef std::uint_least64_t cost_t;
#define COST_INF UINT_LEAST64_MAX

struct Edge {
  int target;
  int distance;
};

struct Node {
  std::vector<Edge> edges;
  cost_t cost;
  bool fixed;

  Node() : cost(COST_INF), fixed(false) {}
};

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

  std::vector<Node> nodes(v);
  nodes[r].cost = 0;

  for (int i = 0; i < e; i++) {
    int s, t, d;
    std::cin >> s >> t >> d;
    nodes[s].edges.push_back({t, d});
  }

  auto less_node = [&](int x, int y) { return nodes[x].cost < nodes[y].cost; };
  std::vector<int> queue;
  queue.push_back(r);

  while (!queue.empty()) {
    auto min = std::min_element(queue.begin(), queue.end(), less_node);
    Node &node = nodes[*min];
    *min = queue.back();
    queue.pop_back();

    if (node.fixed)
      continue;
    node.fixed = true;

    for (Edge e : node.edges) {
      Node &target = nodes[e.target];
      if (!target.fixed) {
        target.cost = std::min(target.cost, node.cost + e.distance);
        queue.push_back(e.target);
      }
    }
  }

  for (Node &node : nodes) {
    if (node.cost == COST_INF)
      std::cout << "INF";
    else
      std::cout << node.cost;
    std::cout << std::endl;
  }

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
#define range(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) range(i, 0, n)
const ll INF = 1e10;
#define pb push_back

struct edge {
  int cost, to;
};

int main() {
  int n, m, r;
  cin >> n >> m >> r;
  vector<vector<edge>> G(n);
  vll d(n, INF);
  rep(i, m) {
    int s;
    edge e;
    cin >> s >> e.to >> e.cost;
    G[s].pb(e);
  }

  priority_queue<pint, vector<pint>, greater<pint>> Q; // 距離,点
  d[r] = 0;
  Q.push(pint(0, r));

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

  rep(i, n) {
    if (d[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
#define range(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) range(i, 0, n)
const ll INF = 1e10;

int main() {
  int n, m, r;
  scanf("%d %d %d", &n, &m, &r);
  int from[500000], to[500000], cost[500000];
  rep(i, m) scanf("%d %d %d", &from[i], &to[i], &cost[i]);

  ll d[100000];
  rep(i, 100000) d[i] = INF;
  d[r] = 0;
  rep(k, n) rep(i, m) d[to[i]] = min(d[to[i]], d[from[i]] + cost[i]);
  rep(i, n) {
    if (d[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
}