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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 10000000
#define INF_LL 1e18
#define REP(i, n) for (int i = 0; i < (n); i++)
#define all(n) n.begin(), n.end()

using namespace std;

using ll = long long;
using PII = pair<int, int>;

int main(void) {
  int V, E, r;
  cin >> V >> E >> r;
  vector<PII> G[100000];
  ll d[100000];
  fill(d, d + 100000, INF_LL);
  REP(i, E) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a].push_back(PII(c, b));
  }
  d[r] = 0;
  priority_queue<PII, vector<PII>, greater<PII>> que;
  que.push(PII(0, r));
  while (que.size()) {
    PII p = que.top();
    que.pop();
    int v = p.second;
    if (p.first > d[v])
      continue;
    REP(i, G[v].size()) {
      if (G[v][i].first + d[v] < d[G[v][i].second]) {
        d[G[v][i].second] = G[v][i].first + d[v];
        que.push(PII(d[G[v][i].second], G[v][i].second));
      }
    }
  }
  REP(i, V) {
    if (d[i] == INF_LL) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 10000000
#define REP(i, n) for (int i = 0; i < (n); i++)
#define all(n) n.begin(), n.end()

using namespace std;

using ll = long long;
using PII = pair<int, int>;

int main(void) {
  int V, E, r;
  cin >> V >> E >> r;
  vector<PII> G[100000];
  int d[100000];
  fill(d, d + 100000, INF);
  REP(i, E) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a - 1].push_back(PII(c, b - 1));
  }
  d[r - 1] = 0;
  priority_queue<PII, vector<PII>, greater<PII>> que;
  que.push(PII(0, r - 1));
  while (que.size()) {
    PII p = que.top();
    que.pop();
    int v = p.second;
    if (p.first > d[v])
      continue;
    REP(i, G[v].size()) {
      if (G[v][i].first + d[v] < d[G[v][i].second]) {
        d[G[v][i].second] = G[v][i].first + d[v];
        que.push(PII(d[G[v][i].second], G[v][i].second));
      }
    }
  }
  REP(i, V) { cout << d[i] << endl; }
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: 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 = 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;
}

Error: MLE

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

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

#define Emax 500001
#define Vmax 100001
#define Dmax 1 << 31

using namespace std;

typedef unsigned int uint;

struct Edge {
  int to, cost;
};

vector<Edge> edges[Vmax];
static uint d[Vmax + 1];
static int Vnum, Enum, r;
static bool visited[Vmax];

void dijkstra() {
  fill_n(d, Vnum + 1, Dmax);
  fill_n(visited, Vnum, false);
  d[r] = 0;
  for (int i = 0; i < Vnum; i++) {
    int u = Vnum;
    for (int j = 0; j < Vnum; j++) {
      if (!visited[j] && d[j] < d[u]) {
        u = j;
      }
    }
    if (u == Vnum) {
      break;
    }
    visited[u] = true;
    for (int j = 0; j < edges[u].size(); j++) {
      auto v = edges[u][j];
      d[v.to] = min(d[v.to], d[u] + v.cost);
    }
  }
}

void dijkstra_priority_queue() {
  auto c = [](int a, int b) { return d[a] > d[b]; };
  priority_queue<int, vector<int>, decltype(c)> Q(c);

  fill_n(d, Vnum, Dmax);
  d[r] = 0;
  for (int i = 0; i < Vnum; i++) {
    Q.push(i);
  }
  while (!Q.empty()) {
    int u = Q.top();
    Q.pop();
    for (int i = 0; i < edges[u].size(); i++) {
      auto v = edges[u][i];
      auto alt = d[u] + v.cost;
      if (d[v.to] > alt) {
        d[v.to] = alt;
        Q.push(v.to);
      }
    }
  }
}

int main(int ac, char **av) {
  scanf("%d %d %d", &Vnum, &Enum, &r);

  for (int i = 0; i < Enum; i++) {
    int s, t, d;
    scanf("%d %d %d", &s, &t, &d);
    Edge e;
    e.to = t;
    e.cost = d;
    edges[s].push_back(e);
  }

  dijkstra_priority_queue();

  for (int i = 0; i < Vnum; i++) {
    if (d[i] == Dmax) {
      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 Emax 500000
#define Vmax 100000
#define Dmax 100000000

using namespace std;

struct Edge {
  int to, cost;
};

vector<Edge> edges[Vmax];
static int d[Vmax + 1];
static int Vnum, Enum, r;
static bool visited[Vmax];

int main(int ac, char **av) {

  fill_n(d, Vmax + 1, Dmax);
  fill_n(visited, Vmax, false);

  cin >> Vnum >> Enum >> r;

  for (int i = 0; i < Enum; i++) {
    int s, t, d;
    scanf("%d %d %d", &s, &t, &d);
    Edge e;
    e.to = t;
    e.cost = d;
    edges[s].push_back(e);
  }
  d[r] = 0;

  for (int i = 0; i < Vnum; i++) {
    int u = Vmax;
    for (int j = 0; j < Vnum; j++) {
      if (!visited[j] && d[j] < d[u]) {
        u = j;
      }
    }
    if (u == Vmax) {
      break;
    }
    visited[u] = true;
    for (Edge v : edges[u]) {
      d[v.to] = min(d[v.to], d[u] + v.cost);
    }
  }
  for (int i = 0; i < Vnum; i++) {
    if (d[i] == Dmax) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long int llg;

const int INF = 1000001000;
#define REP(var, count) for (int var = 0; var < count; var++)

int vert[100010];
int edge[500010][3];

int main(void) {
  int V, E, r;
  scanf("%d", &V);
  scanf("%d", &E);
  scanf("%d", &r);

  REP(v, V) { vert[v] = INF; }
  vert[r] = 0;

  REP(i, E) {
    scanf("%d", &edge[i][0]);
    scanf("%d", &edge[i][1]);
    scanf("%d", &edge[i][2]);
  }

  REP(v, V) {
    bool update = false;
    REP(i, E) {
      int s = edge[i][0];
      int t = edge[i][1];
      if (vert[s] != INF && vert[t] > (vert[s] + edge[i][2])) {
        vert[t] = vert[s] + edge[i][2];
        update = true;
      }
    }
    if (!update) {
      break;
    }
  }

  REP(v, V) {
    if (vert[v] == INF) {
      cout << "INF" << endl;
    } else {
      cout << vert[v] << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long int llg;

const int INF = 100000000;
#define REP(var, count) for (int var = 0; var < count; var++)

int vert[100010];
int edge[500010][3];

int main(void) {
  int V, E, r;
  scanf("%d", &V);
  scanf("%d", &E);
  scanf("%d", &r);

  REP(v, V) { vert[v] = INF; }
  vert[r] = 0;

  REP(i, E) {
    scanf("%d", &edge[i][0]);
    scanf("%d", &edge[i][1]);
    scanf("%d", &edge[i][2]);
  }

  REP(v, V - 1) {
    bool update = false;
    REP(i, E) {
      int s = edge[i][0];
      int t = edge[i][1];
      vert[t] = min(vert[t], vert[s] + edge[i][2]);
      update = true;
    }
    if (!update) {
      break;
    }
  }

  REP(v, V) {
    if (vert[v] == INF) {
      cout << "INF" << endl;
    } else {
      cout << vert[v] << endl;
    }
  }
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
  int v, e, r;
  cin >> v >> e >> r;
  vector<vector<pair<int, int>>> graph(100001);
  for (int i = 0; i < e; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    graph[s].push_back(make_pair(t, d));
  }
  priority_queue<pair<long long int, int>> qu;
  vector<long long int> result(100001, -mod);
  result[r] = 0;
  qu.push(make_pair(0, r));
  while (!qu.empty()) {
    int nowplace = (qu.top()).second;
    long long int nowcost = (qu.top()).first;
    qu.pop();
    if (result[nowplace] > nowcost)
      continue;
    result[nowplace] = nowcost;
    for (int i = 0; i < graph[nowplace].size(); i++) {
      int next = graph[nowplace][i].first;
      long long int cost = graph[nowplace][i].second;
      if (result[next] < nowcost - cost)
        qu.push(make_pair(nowcost - cost, next));
    }
  }
  for (int i = 0; i < v; i++) {
    if (result[i] == -mod)
      cout << "INF" << endl;
    else
      cout << -result[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
  int v, e, r;
  cin >> v >> e >> r;
  vector<vector<pair<int, int>>> graph(100001);
  for (int i = 0; i < e; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    graph[s].push_back(make_pair(t, d));
  }
  priority_queue<pair<long long int, int>> qu;
  vector<long long int> result(100001, mod);
  result[r] = 0;
  qu.push(make_pair(0, r));
  while (!qu.empty()) {
    int nowplace = (qu.top()).second;
    long long int nowcost = (qu.top()).first;
    qu.pop();
    if (result[nowplace] < nowcost)
      continue;
    result[nowplace] = nowcost;
    for (int i = 0; i < graph[nowplace].size(); i++) {
      int next = graph[nowplace][i].first;
      int cost = graph[nowplace][i].second;
      if (result[next] > nowcost + cost)
        qu.push(make_pair(nowcost + cost, next));
    }
  }
  for (int i = 0; i < v; i++) {
    if (result[i] == mod)
      cout << "INF" << endl;
    else
      cout << result[i] << endl;
  }
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 100000000;
const long long int llINF = 1 << 30;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};

vector<edge> graph[1000000];
ll dist[1000000];

int V, E, start;

void bellman(int s) {
  rep(i, V) dist[i] = llINF;
  dist[s] = 0;
  while (true) {
    bool update = false;
    rep(i, E) {
      for (auto e : graph[i]) {
        if (dist[i] != llINF && dist[e.to] > dist[i] + e.cost) {
          dist[e.to] = dist[i] + e.cost;
          update = true;
        }
      }
    }

    if (!update)
      break;
  }
}

int main() {

  cin >> V >> E >> start;
  rep(i, E) {
    int a, t, d;
    cin >> a >> t >> d;
    graph[a].push_back({t, d});
  }

  bellman(start);

  rep(i, V) {
    if (dist[i] != llINF)
      cout << dist[i] << endl;
    else
      cout << "INF" << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 100000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};

vector<edge> graph[100000];
ll dist[100000];

int V, E, start;

void bellman(int s) {
  rep(i, V) dist[i] = iINF;
  dist[s] = 0;
  while (true) {
    bool update = false;
    rep(i, E) {
      for (auto e : graph[i]) {
        if (dist[i] != iINF && dist[e.to] > dist[i] + e.cost) {
          dist[e.to] = dist[i] + e.cost;
          update = true;
        }
      }
    }

    if (!update)
      break;
  }
}

int main() {

  cin >> V >> E >> start;
  rep(i, E) {
    int a, t, d;
    cin >> a >> t >> d;
    graph[a].push_back({t, d});
  }

  bellman(start);

  rep(i, V) {
    if (dist[i] != iINF)
      cout << dist[i] << endl;
    else
      cout << "INF" << endl;
  }
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define INF (INT_MAX / 2)
#define PI (2 * acos(0.0))
#define EPS (1e-8)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst;
  Cost cst;
  Edge(int s, int d, Cost c) : src(s), dst(d), cst(c) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Cost> Array;
typedef vector<Array> Matrix;

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

vector<Cost> dijkstra(const Graph &g, int s) {
  const Cost inf = numeric_limits<Cost>::max() / 2;
  typedef tuple<Cost, int> State;
  priority_queue<State> q;
  vector<Cost> dist(g.size(), inf);
  dist[s] = 0;
  q.emplace(0, s);
  while (q.size()) {
    Cost c;
    int v;
    tie(c, v) = q.top();
    q.pop();
    c *= -1;
    if (dist[v] < c)
      continue;
    for (auto &e : g[v]) {
      if (dist[e.dst] > dist[v] + e.cst) {
        dist[e.dst] = dist[v] + e.cst;
        q.emplace(-dist[e.dst], e.dst);
      }
    }
  }
  return dist;
}

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int v, e, r;
  int s, t, d;

  cin >> v >> e >> r;

  Graph g(v);
  for (int i = 0; i < e; i++) {
    cin >> s >> t >> d;
    g[s].push_back(Edge(s, t, d));
  }

  vector<Cost> c = dijkstra(g, r);
  for (int i = 0; i < (int)c.size(); i++) {
    if (c[i] == numeric_limits<Cost>::max() / 2)
      cout << "INF" << endl;
    else
      cout << c[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define INF (INT_MAX / 2)
#define MAX_E 500000
#define MAX_V 100000

struct edge {
  int from, to, cost;
  edge() {}
  edge(int f, int t, int c) {
    from = f;
    to = t;
    cost = c;
  }
};
edge es[MAX_E];

int dist[MAX_V];
int previous[MAX_V];
int V, E, r;

bool bellman_ford(int s) {
  for (int i = 0; i < V; i++)
    dist[i] = INF;
  dist[s] = 0;
  previous[s] = -1;

  for (int i = 0; i < V; i++) {
    for (int j = 0; j < E; j++) {
      edge e = es[j];
      if (dist[e.to] > dist[e.from] + e.cost) {
        dist[e.to] = dist[e.from] + e.cost;
        previous[e.to] = e.from;
        if (i == V - 1)
          return true;
      }
    }
  }

  return false;
}

vector<int> get_path(int t) {
  vector<int> path;
  for (; t != -1; t = previous[t])
    path.push_back(t);
  reverse(path.begin(), path.end());
  return path;
}

int main(void) {
  cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    es[i] = edge(s, t, d);
  }
  bellman_ford(r);
  for (int i = 0; i < V; i++) {
    if (dist[i] == INF)
      cout << "INF" << endl;
    else
      cout << dist[i] << endl;
  }
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

#define INF 334334334334
const int MAX_V = 100005;

struct edge {
  int to, cost;
};
typedef pair<int, int> P; // first:???????????¢???second:???????????????
vector<edge> G[MAX_V];
long long int d[MAX_V];
int V, E, s;

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

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

int main() {
  scanf("%d%d%d", &V, &E, &s);
  for (int i = 0; i < E; i++) {
    int from, to, cost;
    scanf("%d", &from);
    scanf("%d", &to);
    scanf("%d", &cost);
    edge e;
    e.to = to;
    e.cost = cost;
    G[from].push_back(e);
  }

  dijkstra(s);

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

Error: 0

Fixed submission:

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

using namespace std;

#define MAX_V 1000
#define INF 1000000000

struct edge {
  int to, cost;
};
typedef pair<int, int> P; // first:???????????¢???second:???????????????
vector<edge> G[MAX_V];
int d[MAX_V];
int V, E, s;

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

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

int main() {
  scanf("%d%d%d", &V, &E, &s);
  for (int i = 0; i < E; i++) {
    int from, to, cost;
    scanf("%d", &from);
    scanf("%d", &to);
    scanf("%d", &cost);
    edge e;
    e.to = to;
    e.cost = cost;
    G[from].push_back(e);
  }

  dijkstra(s);

  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: Memory Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#define lint long long
#define REP(i, x, n) for (lint i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (lint i = n - 1; i >= 0; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

const lint MAX = 1e17;
lint v, e, r;
vector<vector<pair<lint, lint>>> g;
vector<lint> dis;
vector<bool> done;

void dijkstra(lint start) {
  dis[start] = 0;
  priority_queue<pair<lint, lint>, vector<pair<lint, lint>>,
                 greater<pair<lint, lint>>>
      dij;
  dij.push(make_pair(0, start));
  while (!dij.empty()) {
    pair<lint, lint> tmp = dij.top();
    dij.pop();
    if (done[tmp.second]) {
      continue;
    }
    done[tmp.second] = true;
    rep(i, g[tmp.second].size()) {
      if (dis[g[tmp.second][i].first] >
          dis[tmp.second] + g[tmp.second][i].second) {
        dis[g[tmp.second][i].first] = dis[tmp.second] + g[tmp.second][i].second;
        dij.push(
            make_pair(dis[g[tmp.second][i].first], g[tmp.second][i].first));
      }
    }
  }
  return;
}

int main() {
  cin >> v >> e >> r;
  g.resize(v);
  rep(i, e) {
    lint s, t, d;
    cin >> s >> t >> d;
    g[s].push_back(make_pair(t, d));
  }
  dis.resize(v, MAX);
  done.resize(v, false);
  dijkstra(r);
  rep(i, v) {
    if (dis[i] == MAX) {
      cout << "INF" << endl;
    } else {
      cout << dis[i] << endl;
    }
  }
  return 0;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

typedef long long lint;

const lint M = 1e17;

int main() {
  lint n, m, r;
  cin >> n >> m >> r;
  vector<lint> dis(n, M);
  dis[r] = 0;
  map<pair<lint, lint>, lint> mp;
  vector<vector<bool>> road(n);
  for (lint i = 0; i < n; i++) {
    road[i].resize(n, false);
  }
  for (lint i = 0; i < m; i++) {
    lint a, b, c;
    cin >> a >> b >> c;
    pair<lint, lint> p = make_pair(a, b);
    mp[p] = c;
    road[a][b] = true;
  }
  vector<bool> done(n, false);
  done[r] = true;
  lint tmp = r;
  bool flag = true;
  while (flag) {
    for (lint j = 0; j < n; j++) {
      pair<lint, lint> p = make_pair(tmp, j);
      if (!done[j] && road[tmp][j]) {
        dis[j] = min(dis[j], dis[tmp] + mp[p]);
      }
    }
    lint t = M;
    flag = false;
    for (lint j = 0; j < n; j++) {
      if (!done[j]) {
        if (t > dis[j]) {
          t = dis[j];
          tmp = j;
          flag = true;
        }
      }
    }
    done[tmp] = true;
  }
  for (lint i = 0; i < n; i++) {
    if (dis[i] == M) {
      cout << "INF" << endl;
    } else {
      cout << dis[i] << endl;
    }
  }
  return 0;
}