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

#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;
typedef pair<int, int> P;
const int INF = 2100000000;

struct edge {
  int to, cost;
};

int V, E, r;
int d[100010];
vector<edge> G[100010];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, s));
  fill(d, d + V, INF);
  d[s] = 0;
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (auto e : G[v]) {
      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(void) {
  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] < INF)
      cout << d[i] << endl;
    else
      cout << "INF" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 28;

struct edge {
  int to, cost;
};

int V, E, r;
int d[10010];
vector<edge> G[10010];

void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, s));
  fill(d, d + V, INF);
  d[s] = 0;
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (auto e : G[v]) {
      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(void) {
  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] < INF)
      cout << d[i] << endl;
    else
      cout << "INF" << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> P;
const int INF = 1e9 + 10;
const int N = 1e5 + 10;

struct edge {
  int to, cost;
  edge() {}
  edge(int t, int c) : to(t), cost(c) {}
};

vector<edge> G[N];
int V, E, S;
int d[N];

void init(int n) {
  for (int i = 0; i <= n; i++)
    G[i].clear();
}

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

  while (!q.empty()) {
    P tmp = q.top();
    q.pop();
    int v = tmp.second;
    if (d[v] < tmp.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[v] != INF) {
        d[e.to] = d[v] + e.cost;
        q.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  while (scanf("%d %d %d", &V, &E, &S) != EOF) {
    init(V);
    for (int i = 0; i < E; i++) {
      int s, t, c;
      scanf("%d %d %d", &s, &t, &c);
      G[s].push_back(edge(t, c));
    }
    Dijkstra(S);
    for (int i = 0; i < V; i++) {
      if (d[i] == INF) {
        puts("INF");
        continue;
      }
      printf("%d\\n", d[i]);
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9 + 10;
const int N = 1e5 + 10;

struct edge {
  int to, cost;
  edge(int _to = 0, int _cost = 0) : to(_to), cost(_cost) {}
};

vector<edge> G[N];
int d[N];
int V, E, S;

void init(int n) {
  for (int i = 0; i <= n; i++) {
    G[i].clear();
  }
}
bool Bellman_Ford(int s) {
  fill(d, d + V, INF);
  d[s] = 0;

  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      for (int k = 0; k < G[j].size(); k++) {
        edge &e = G[j][k];
        if (d[e.to] > d[j] + e.cost) {
          d[e.to] = d[j] + e.cost;
          if (i == V - 1)
            return true;
        }
      }
    }
  }
  return false;
}

int main() {
  while (scanf("%d %d %d", &V, &E, &S) != EOF) {
    init(V);
    for (int i = 0; i < E; i++) {
      int s, t, c;
      scanf("%d %d %d", &s, &t, &c);
      G[s].push_back(edge(t, c));
    }
    Bellman_Ford(S);
    for (int i = 0; i < V; i++) {
      if (d[i] == INF) {
        puts("INF");
        continue;
      }
      printf("%d\\n", d[i]);
    }
  }

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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define MAXV 100000
#define INF 1e9

int V, E, r;
struct edge {
  int to, cost;
};
typedef pair<int, int> P; // firstは最短距離、secondは頂点番号

vector<edge> G[MAXV];
int d[MAXV];

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(void) {
  cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    edge e;
    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 << d[i] << endl;
    else
      cout << "INF" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
vector<vector<int>> edge;
vector<vector<int>> dist;
int V, E, r;
int main() {
  cin >> V >> E >> r;
  edge.resize(V);
  dist.resize(V);
  for (int i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    edge[s].push_back(t);
    dist[s].push_back(d);
  }
  int MAX = 1e9;
  int d[V];
  bool check[V];
  for (int i = 0; i < V; i++) {
    d[i] = MAX;
    check[i] = false;
  }
  d[r] = 0;
  for (int i = 0; i < V; i++) {
    int now = 0;
    int nowd = MAX;
    for (int j = 0; j < V; j++) {
      if (nowd > d[j] && !check[j]) {
        nowd = d[j];
        now = j;
      }
    }
    if (nowd == MAX)
      break;
    check[now] = true;
    for (int j = 0; j < edge[now].size(); j++) {
      int next = edge[now][j];
      int nextd = d[now] + dist[now][j];
      if (nextd < d[next]) {
        d[next] = nextd;
      }
    }
  }
  for (int i = 0; i < V; i++) {
    if (d[i] < MAX)
      cout << d[i] << endl;
    else
      cout << "INF" << endl;
  }
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

#define INF (1 << 30)
typedef pair<int, int> P;
struct Edge {
  int to, cost;
};
vector<vector<Edge>> Graph;

void Dijkstra(int s, int g) {
  vector<int> min_cost(Graph.size(), INF);
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, s));
  min_cost[s] = 0;
  while (!que.empty()) {
    int cost = que.top().first;
    int now = que.top().second;
    que.pop();
    // if(now == g) return cost;
    if (cost > min_cost[now])
      continue;
    for (int i = 0; i < Graph[now].size(); i++) {
      Edge e = Graph[now][i];
      if (cost + e.cost < min_cost[e.to]) {
        min_cost[e.to] = cost + e.cost;
        que.push(P(min_cost[e.to], e.to));
      }
    }
  }
  for (int i = 0; i < g; i++) {
    if (min_cost[i] == INF)
      cout << "INF" << endl;
    else
      cout << min_cost[i] << endl;
  }
  // return (-1);
}

int main() {
  int V, E, r;
  cin >> V >> E >> r;
  Graph.resize(V);
  for (int i = 0; i < E; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    Edge e;
    e.to = b;
    e.cost = c;
    Graph[a].push_back(e);
    // e.to = a;
    // Graph[b].push_back(e);
  }
  Dijkstra(r, V);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

#define INF (1 << 30)
typedef pair<int, int> P;
struct Edge {
  int to, cost;
};
vector<vector<Edge>> Graph;

int Dijkstra(int s, int g) {
  vector<int> min_cost(Graph.size(), INF);
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, s));
  min_cost[s] = 0;
  while (!que.empty()) {
    int cost = que.top().first;
    int now = que.top().second;
    que.pop();
    if (now == g)
      return cost;
    if (cost > min_cost[now])
      continue;
    for (int i = 0; i < Graph[now].size(); i++) {
      Edge e = Graph[now][i];
      if (cost + e.cost < min_cost[e.to]) {
        min_cost[e.to] = cost + e.cost;
        que.push(P(min_cost[e.to], e.to));
      }
    }
  }
  return (-1);
}

int main() {
  int V, E, r;
  cin >> V >> E >> r;
  Graph.resize(V);
  for (int i = 0; i < E; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    Edge e;
    e.to = b;
    e.cost = c;
    Graph[a].push_back(e);
    // e.to = a;
    // Graph[b].push_back(e);
  }
  for (int i = 0; i < V; i++) {
    int ans = Dijkstra(r, i);
    if (ans == -1)
      cout << "INF" << endl;
    else
      cout << ans << endl;
  }
}
Problem p02361 (C++) — buggy submission, verdict: 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 (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;
}

Error: TLE

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

Error: 0

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

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#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--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
struct poi {
  int to, cost;
  poi(int t, int c) {
    to = t;
    cost = c;
  }
};
vector<ll> d;
vector<vector<poi>> edges;
int V, E, r;
ll INF = 5000000000;

/*bool berm(){
  for(int ct=0;ct<V;ct++){
    for(int i=0;i<E;i++){
      int v = edges[i].to;
      int u = edges[i].from;
      int c = edges[i].cost;
      if(d[u] + c < d[v]){
        d[v] = d[u] + c;
                if(ct == V-1){
          return false;
          }
      }
    }
  }
  return true;
  }*/
typedef pair<int, int> P;
int dijk() {
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(0, 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 < edges[v].size(); i++) {
      poi e = edges[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.tie(0);
  ios::sync_with_stdio(false);
  cin >> V >> E >> r; // V is number of point,E is number of hen,r is defpoint
  d.resize(V, INF);
  d[r] = 0;
  edges.resize(V, vector<poi>());
  REP(i, E) {
    int from, to, cost;
    cin >> from >> to >> cost;
    edges[from].push_back(poi(to, cost));
  }
  dijk();
  REP(i, V)
  if (d[i] == INF)
    cout << "INF" << endl;
  else
    cout << d[i] << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#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--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
struct poi {
  int to, from, cost;
};
vector<int> d;
vector<poi> edges;
int V, E, r;
int INF = 100000000;

bool belman() {
  for (int ct = 0; ct < V; ct++) {
    for (int i = 0; i < E; i++) {
      int v = edges[i].to;
      int u = edges[i].from;
      int c = edges[i].cost;
      if (d[u] + c < d[v]) {
        d[v] = d[u] + c;
        /*	if(ct == V-1){
          return false;
          }*/
      }
    }
  }
  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> V >> E >> r; // V is number of point,E is number of hen,r is defpoint
  d.resize(V, INF);
  d[r] = 0;
  edges.resize(E);
  REP(i, E) { cin >> edges[i].from >> edges[i].to >> edges[i].cost; }
  belman();
  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 <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;
}

Error: TLE

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, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reg(i, a, b) for (int i = (a); i <= (b); i++)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second

int dijkstra(int n, int s, vector<mp> *vs, int *dist, int g = -1) {
  memset(dist, -1, sizeof(int) * n);
  // rep(i,n)dist[i]=-1;
  priority_queue<mp, vector<mp>, greater<mp>> que;
  que.push(mp(0, s));
  while (!que.empty()) {
    mp pa = que.top();
    que.pop();
    int co = pa.fir, no = pa.sec;
    if (dist[no] != -1 && dist[no] < co)
      continue;
    dist[no] = co;
    if (no == g)
      return co;
    rep(i, vs[no].size()) {
      mp pb = vs[no][i];
      int to = pb.fir, tc = co + pb.sec;
      if (dist[to] != -1 && dist[to] <= tc)
        continue;
      dist[to] = tc;
      que.push(mp(tc, to));
    }
  }
  return -1;
}

int n, m;

vector<mp> vs[100005];

int dist[100005];

int main(void) {
  int n, m, s;
  scanf("%d%d%d", &n, &m, &s);
  rep(i, m) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    vs[a].push_back(mp(b, c));
    // vs[b].push_back(mp(a,c));
  }
  dijkstra(n, s, vs, dist);
  rep(i, n) {
    if (dist[i] != -1)
      printf("%d\\n", dist[i]);
    else
      printf("INF\\n");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reg(i, a, b) for (int i = (a); i <= (b); i++)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second

int dijkstra(int n, int s, vector<mp> *vs, int *dist, int g = -1) {
  memset(dist, -1, sizeof(int) * n);
  // rep(i,n)dist[i]=-1;
  priority_queue<mp, vector<mp>, greater<mp>> que;
  que.push(mp(0, s));
  while (!que.empty()) {
    mp pa = que.top();
    que.pop();
    int co = pa.fir, no = pa.sec;
    if (dist[no] != -1 && dist[no] < co)
      continue;
    dist[no] = co;
    if (no == g)
      return co;
    rep(i, vs[no].size()) {
      mp pb = vs[no][i];
      int to = pb.fir, tc = co + pb.sec;
      if (dist[to] != -1 && dist[to] <= tc)
        continue;
      dist[to] = tc;
      que.push(mp(tc, to));
    }
  }
  return -1;
}

int n, m;

vector<mp> vs[5005];

int dist[5005];

int main(void) {
  int n, m, s;
  scanf("%d%d%d", &n, &m, &s);
  rep(i, m) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    vs[a].push_back(mp(b, c));
    // vs[b].push_back(mp(a,c));
  }
  dijkstra(n, s, vs, dist);
  rep(i, n) {
    if (dist[i] != -1)
      printf("%d\\n", dist[i]);
    else
      printf("INF\\n");
  }
  return 0;
}