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

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

struct Edge {
  int to, cost;
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef pair<int, int> Pii;

int const INF = INT_MAX / 2;

Graph G;

int main() {

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

  int dist[V];
  fill(dist, dist + V, INF);
  dist[r] = 0;
  priority_queue<Pii> pq;
  pq.push(Pii(0, r));
  while (!pq.empty()) {
    const Pii pii = pq.top();
    pq.pop();
    const int cost = -pii.first;
    const int now = pii.second;
    if (dist[now] < cost)
      continue;
    for (int i = 0; i < (int)G[now].size(); i++) {
      const Edge &e = G[now][i];
      if (dist[e.to] > cost + e.cost) {
        dist[e.to] = cost + e.cost;
        pq.push(Pii(-dist[e.to], e.to));
      }
    }
  }

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

  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
struct Edge {
  int to;
  ll cost;
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef pair<ll, int> Plli;

ll const INF = LLONG_MAX / 4;

Graph G;

int main() {

  int V, E, r;
  cin >> V >> E >> r;
  G.resize(V);
  for (int i = 0; i < E; i++) {
    int s, t;
    ll d;
    cin >> s >> t >> d;
    G[s].push_back((Edge){t, d});
  }

  ll dist[V];
  fill(dist, dist + V, INF);
  dist[r] = 0;
  priority_queue<Plli> pq;
  pq.push(Plli(0, r));
  while (!pq.empty()) {
    const Plli plli = pq.top();
    pq.pop();
    const ll cost = plli.first;
    const int now = plli.second;
    if (dist[now] < cost)
      continue;
    for (int i = 0; i < G[now].size(); i++) {
      const Edge &e = G[now][i];
      if (dist[e.to] > cost + e.cost) {
        dist[e.to] = cost + e.cost;
        pq.push(Plli(dist[e.to], e.to));
      }
    }
  }

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

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

Error: TLE

Fixed submission:

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

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

using namespace std;

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

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

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

Error: TLE

Fixed submission:

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

using namespace std;

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

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

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

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

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
#define MAX_V 100010
struct edge {
  int to, cost;
};
vector<vector<edge>> G(MAX_V);
int V, E, s;
void dijkstra() {
  vi d(MAX_V);
  rep(i, MAX_V) d[i] = inf;
  d[s] = 0;
  priority_queue<pii> q;
  q.push(pii(0, s));
  while (!q.empty()) {
    pii p = q.top();
    q.pop();
    int pos = p.second, cost = -p.first;
    if (cost > d[pos])
      continue;
    rep(i, G[pos].size()) {
      edge e = G[pos][i];
      int to = e.to;
      int nowcost = cost + e.cost;
      if (nowcost < d[to]) {
        d[to] = nowcost;
        q.push(pii(-d[to], to));
      }
    }
  }
  rep(i, V) if (d[i] == inf) cout << "INF" << endl;
  else cout << d[i] << endl;
}
int main() {
  cin >> V >> E >> s;
  while (E--) {
    int a, b, c;
    cin >> a >> b >> c;
    edge t = {b, c};
    G[a].pb(t);
  }
  dijkstra();
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
int main() {
  int n, m, s;
  cin >> n >> m >> s;
  vvi cost(n, vi(n, inf));
  vi d(n, inf);
  d[s] = 0;
  vi used(n);
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    cost[a][b] = c;
  }
  while (1) {
    int v = -1;
    rep(i, n) if (!used[i] && (v == -1 || d[v] > d[i])) v = i;
    if (v == -1)
      break;
    used[v] = true;
    rep(i, n) d[i] = min(d[i], d[v] + cost[v][i]);
  }
  rep(i, n) if (d[i] == inf) cout << "INF" << endl;
  else cout << d[i] << endl;
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int V, E, r, s, t, din;
  vector<int> d, weight;
  vector<pair<int, int>> edge;

  cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    cin >> s >> t >> din;
    edge.push_back(make_pair(s, t));
    weight.push_back(din);
  }

  for (int i = 0; i < V; i++) {
    d.push_back(1000000000);
  }
  if (d.size())
    d[r] = 0;
  if (!d.size())
    d.push_back(0);

  for (int i = 1; i < V; i++) {
    bool update = false;
    for (int j = 0; j < E; j++) {
      int oldd = d[edge[j].second];
      d[edge[j].second] = min(d[edge[j].second], d[edge[j].first] + weight[j]);

      if (oldd != d[edge[j].second])
        update = true;
    }
    if (!update)
      break;
  }
  for (int i = 0; i < V; i++) {
    if (d[i] == 1000000000) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int d[500010], weight[500010];
pair<int, int> edge[500010];

int main() {
  int V, E, r, s, t, din;

  cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    cin >> s >> t >> din;
    edge[i] = make_pair(s, t);
    weight[i] = din;
  }

  for (int i = 0; i < V; i++) {
    d[i] = 10000000;
  }

  d[r] = 0;
  for (int i = 0; i < V; i++) {
    bool update = false;
    for (int j = 0; j < E; j++) {
      d[edge[j].second] = min(d[edge[j].second], d[edge[j].first] + weight[j]);
      update = true;
    }
    if (!update)
      break;
  }
  for (int i = 0; i < V; i++) {
    if (d[i] == 10000000) {
      cout << "INF" << endl;
    } else {
      cout << d[i] << endl;
    }
  }
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define inf 1e9 + 1
typedef pair<int, int> mypair;
int main() {
  int v, e, r;
  cin >> v >> e >> r;
  vector<vector<mypair>> g(v);
  int s, t, d;
  for (int i = 0; i < e; i++) {
    cin >> s >> t >> d;
    g[s].push_back(mypair(t, d));
  }
  priority_queue<mypair, vector<mypair>, greater<mypair>> q;
  vector<int> ans(v, inf);
  q.push(mypair(0, r));
  while (!q.empty()) {
    mypair now = q.top();
    q.pop();
    if (now.first > ans[now.second])
      continue;
    else {
      ans[now.second] = now.first;
      for (int i = 0; i < g[now.second].size(); i++) {
        q.push(mypair(now.first + g[now.second][i].second,
                      g[now.second][i].first));
      }
    }
  }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define INF (1e9 + 1)
#define M 1000000
#define F(i, s, e) for (int i = s; i < e; i++)
struct edge {
  int to, cost;
};
typedef pair<int, int> mypair;
void solve(vector<int> ans, vector<vector<edge>> g, int r, int v) {
  //		priority_queue<mypair,vector<mypair>,greater<mypair> > q;
  priority_queue<mypair> q;
  q.push(mypair(0, r));
  while (!q.empty()) {
    mypair temp = q.top();
    q.pop();
    int now = temp.second;
    int cost = temp.first;
    if (cost > ans[now])
      continue;
    for (int i = 0; i < g[now].size(); i++) {
      edge a = g[now][i];
      int to = a.to;
      if (cost + a.cost < ans[to]) {
        ans[to] = cost + a.cost;
        q.push(mypair(ans[to], to));
      }
    }
  }
  for (int i = 0; i < v; i++) {
    if (ans[i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << ans[i] << endl;
    }
  }
  return;
}
int main(void) {
  int v, e, r;
  cin >> v >> e >> r;
  vector<int> s(e), t(e), d(e);
  vector<int> ans(v, INF);
  ans[r] = 0;
  vector<vector<edge>> g(v);
  for (int i = 0; i < e; i++) {
    cin >> s[i] >> t[i] >> d[i];
    g[s[i]].push_back(((edge){t[i], d[i]}));
  }
  solve(ans, g, r, v);
  /*for(int i=0;i<v;i++){
          if(ans[i]==INF){
                  cout<<"INF"<<endl;
          }else{
                  cout<<ans[i]<<endl;
          }
  }*/
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
// #include "MyMath.h"
// #include "MyDisjointset.h"
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
typedef pair<int, int> P;
const int INF = 1000000000;
struct edge {
  int from, to, cost;
};
int main() {
  int v, e, r;
  cin >> v >> e >> r;
  vector<edge> ed;
  for (int i = 0; i < e; i++) {
    int s, t, co;
    cin >> s >> t >> co;
    edge e1;
    e1.from = s;
    e1.to = t;
    e1.cost = co;
    ed.push_back(e1);
  }
  int *d = new int[v];
  fill(d, d + v, INF);
  d[r] = 0;
  while (true) {
    bool update = false;
    for (int i = 0; i < ed.size(); i++) {
      edge ex = ed[i];
      if (d[ed[i].from] != INF && d[ed[i].to] > d[ed[i].from] + ex.cost) {
        d[ed[i].to] = d[ed[i].from] + ex.cost;
        // cout << "from " << d[ed[i].from] << " to " << d[ed[i].to] << " cost "
        // << ex.cost << endl;
        update = true;
      }
    }
    if (!update)
      break;
  }
  for (int i = 0; i < v; i++) {
    if (d[i] == INF)
      cout << "INF" << endl;
    else
      cout << d[i] << endl;
  }
  delete[] d;
  return 0;
}

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
// #include "MyMath.h"
// #include "MyDisjointset.h"
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
typedef pair<int, int> P;
const int INF = 1000000000;
struct edge {
  int from, to, cost;
};
int main() {
  int v, e, r;
  cin >> v >> e >> r;
  vector<edge> ed;
  for (int i = 0; i < e; i++) {
    int s, t, co;
    cin >> s >> t >> co;
    edge e1;
    e1.from = s;
    e1.to = t;
    e1.cost = co;
    ed.push_back(e1);
  }
  // int *d = new int[v];
  int d[1001];
  fill(d, d + v, INF);
  d[r] = 0;
  while (true) {
    bool update = false;
    for (int i = 0; i < ed.size(); i++) {
      edge ex = ed[i];
      if (d[ed[i].from] != INF && d[ed[i].to] > d[ed[i].from] + ex.cost) {
        d[ed[i].to] = d[ed[i].from] + ex.cost;
        // cout << "from " << d[ed[i].from] << " to " << d[ed[i].to] << " cost "
        // << ex.cost << endl;
        update = true;
      }
    }
    if (!update)
      break;
  }
  for (int i = 0; i < v; i++) {
    if (d[i] == INF)
      cout << "INF" << endl;
    else
      cout << d[i] << endl;
  }
  // delete[] d;
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
const int INF = 10000 * 100000 + 100;
int V, E, R, S[500010], T[500010], D[500010];
int C[100010];
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 t = 0; t < V; ++t) {
    bool update = false;
    for (int i = 0; i < E; ++i) {
      int s = S[i], t = T[i], d = D[i];
      if (C[s] < INF && C[t] > C[s] + D[i]) {
        C[t] = C[s] + D[i];
        update = true;
      }
    }
    if (!update)
      break;
  }
  for (int i = 0; i < V; i++) {
    if (C[i] == INF)
      cout << "INF" << endl;
    else
      cout << C[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
const int maxnum = 100;
const int INF = 99999;

typedef struct Edge {
  int u, v;
  int weight;
} Edge;

Edge edge[maxnum];
int dist[maxnum];

int V, E, r;

void init() {
  cin >> V >> E >> r;
  for (int i = 0; i < V; ++i) {
    dist[i] = INF;
  }
  dist[r] = 0;
  for (int i = 0; i < E; ++i) {
    cin >> edge[i].u >> edge[i].v >> edge[i].weight;
    if (edge[i].u == r)
      dist[edge[i].v] = edge[i].weight;
  }
}

//??????
void relax(int u, int v, int weight) {
  if (dist[v] > dist[u] + weight)
    dist[v] = dist[u] + weight;
}

bool Bellman_Ford() {
  for (int i = 0; i < V - 1; ++i)
    for (int j = 0; j < E; ++j)
      relax(edge[j].u, edge[j].v, edge[j].weight);
  bool flag = 1;
  for (int i = 0; i < E; ++i)
    if (dist[edge[i].v] > dist[edge[i].u] + edge[i].weight) {
      flag = 0;
      break;
    }
  return flag;
}
int main() {
  init();
  if (Bellman_Ford())
    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: Time Limit Exceeded

#include <iostream>
#include <queue>
#include <utility>
using namespace std;

long int inf = 100000 * 100000 + 100;
int main() {
  int v, e, r;
  int s[500000];
  int t[500000];
  int d[500000];
  long int dis[100000];
  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++) {
    dis[i] = inf;
  }
  dis[r] = 0;

  for (int i = 0; i < v - 1; i++) {
    int end = 1;
    for (int j = 0; j < e; j++) {
      if (dis[t[j]] > dis[s[j]] + d[j]) {
        dis[t[j]] = dis[s[j]] + d[j];
        end = 0;
      }
    }

    if (end == 1)
      break;
  }

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

Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#include <utility>
using namespace std;

long int inf = 100000 * 100000 + 100;
int main() {
  int v, e, r;
  int s[500000];
  int t[500000];
  int d[500000];
  long int dis[100000];
  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++) {
    dis[i] = inf;
  }
  dis[r] = 0;

  for (int i = 0; i < v - 1; i++) {
    for (int j = 0; j < e; j++) {
      dis[t[j]] = min(dis[t[j]], dis[s[j]] + d[j]);
    }
  }

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