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

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
using namespace std;

typedef pair<int, int> P;

vector<P> edge[100000];
priority_queue<P, vector<P>, greater<P>> que;
int cost[100000];
int V, E, r;
const int INF = 999999999;

void dijkstra() {
  for (int i = 0; i < 100000; i++) {
    cost[i] = INF;
  }

  cost[r] = 0;
  que.push(P(r, 0));

  while (!que.empty()) {
    P now = que.top();
    que.pop();

    for (int i = 0; i < edge[now.first].size(); i++) {
      int to = edge[now.first][i].first;
      int c = now.second + edge[now.first][i].second;
      if (cost[to] > c) {
        cost[to] = c;
        que.push(P(to, c));
      }
    }
  }
}

int main() {
  cin >> V >> E >> r;

  for (int i = 0; i < E; i++) {
    int from, to, d;
    cin >> from >> to >> d;
    edge[from].push_back(P(to, d));
  }

  dijkstra();

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

  return 0;
}

Error: TLE

Fixed submission:

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

class Edge {
public:
  int to, cost;
  Edge(const Edge &edge) : to(edge.to), cost(edge.cost) {}
  Edge(int to = 0, int cost = 0) : to(to), cost(cost) {}
};
class Node {
public:
  int n, cost;
  Node(const Node &node) : n(node.n), cost(node.cost) {}
  Node(int n = 0, int cost = 0) : n(n), cost(cost) {}
};
bool operator>(const Node &a, const Node &b) { return a.cost < b.cost; }

const int INF = 99999999;
int cost[100000];
vector<Edge> edges[100000];
priority_queue<Node, vector<Node>, greater<Node>> que;

void dijkstra(int V, int E, int startNode) {
  //?????????
  for (int i = 0; i < V; i++) {
    cost[i] = INF;
  }
  //??????????????????
  que.push(Node(startNode, 0));
  cost[startNode] = 0;
  while (!que.empty()) {
    Node nowNode = que.top();
    que.pop();

    for (int i = 0; i < edges[nowNode.n].size(); i++) {
      Edge e = edges[nowNode.n][i];
      if (cost[e.to] <= nowNode.cost + e.cost)
        continue;
      cost[e.to] = nowNode.cost + e.cost;
      que.push(Node(e.to, nowNode.cost + e.cost));
    }
  }
}

int main() {
  //????????° ?????° ??????????????°????????\\???
  int V, E, startPos;
  cin >> V >> E >> startPos;

  //????????±?????\\???
  for (int i = 0; i < E; i++) {
    int from, to, cost;
    cin >> from >> to >> cost;
    edges[from].push_back(Edge(to, cost));
  }

  dijkstra(V, E, startPos);

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

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

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

struct E {
  int t;
  int d;
  E(int _t, int _d) {
    t = _t;
    d = _d;
  }
};

struct V {
  int cost = -1;
  vector<E> es;
};

typedef vector<V> G;

typedef pair<int, int> P;

int main(int argc, char *argv[]) {
  int v, e, r;
  cin >> v >> e >> r;
  G graph(v);
  for (int i = 0; i < e; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    graph[s].es.push_back(E(t, d));
  }

  priority_queue<P> q;
  q.push(P(r, 0));
  graph[r].cost = 0;

  while (!q.empty()) {
    P next = q.top();
    q.pop();
    int v = next.first;
    int hereCost = next.second;
    for (auto e : graph[v].es) {
      int cost = e.d;
      int newCost = hereCost + cost;
      int oldCost = graph[e.t].cost;
      if (newCost < oldCost || oldCost == -1) {
        graph[e.t].cost = newCost;
        q.push(P(e.t, newCost));
      }
    }
  }

  for (auto v : graph) {
    int d = v.cost;
    if (d == -1) {
      cout << "INF" << endl;
    } else {
      cout << d << endl;
    }
  }

  return 0;
}

Error: MLE

Fixed submission:

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

struct Node {
  int v;
  int d;
  Node(int v_, int d_) {
    v = v_;
    d = d_;
  }
};

bool operator<(const Node &l, const Node &r) { return l.d > r.d; }

vector<Node> neighbors(int v, const vector<vector<int>> &graph,
                       vector<int> &vs) {
  vector<Node> ns;
  for (int i = 0; i < graph[v].size(); i++) {
    int cost = graph[v][i];
    if (cost == -1) {
      continue;
    }
    int newCost = cost + vs[v];
    if (newCost < vs[i] || vs[i] == -1) {
      vs[i] = newCost;
      ns.push_back(Node(i, newCost));
    }
  }
  return ns;
}

int main(int argc, char *argv[]) {
  int V, E, r;
  cin >> V >> E >> r;
  vector<vector<int>> graph(V, vector<int>(V, -1));
  vector<int> vs(V, -1);
  for (int i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    graph[s][t] = d;
  }

  priority_queue<Node> q;
  q.push(Node(r, 0));
  vs[r] = 0;

  while (!q.empty()) {
    Node next = q.top();
    q.pop();
    vector<Node> ns = neighbors(next.v, graph, vs);
    for (auto n : ns) {
      q.push(n);
    }
  }

  for (int d : vs) {
    if (d == -1) {
      cout << "INF" << endl;
    } else {
      cout << d << endl;
    }
  }

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

#include <iostream>
#include <vector>
#define MIN(a, b) ((a < b) ? a : b)
#define INF 1000000001
#define N 100000

using namespace std;

struct edge {
  int source;
  int target;
  int weight;
};

vector<edge> edges;

int distances[N];
int prev_distances[N] = {0};

int main() {
  int V, E, r;

  cin >> V >> E >> r;

  for (int i = 0; i < E; i++) {
    int source, target, distance;
    cin >> source >> target >> distance;
    edge new_edge = {source, target, distance};
    edges.push_back(new_edge);
  }

  // initialize distances array

  for (int i = 0; i < N; i++) {
    distances[i] = INF; // max value
  }

  distances[r] = 0;

  for (int i = 1; i < V; i++) {
    for (int j = 0; j < V; j++) {
      prev_distances[j] = distances[j];
    }

    for (vector<edge>::iterator edgeptr = edges.begin(); edgeptr != edges.end();
         edgeptr++) {
      distances[edgeptr->target] =
          MIN(distances[edgeptr->source] + edgeptr->weight,
              distances[edgeptr->target]);
    }

    bool same = true;
    for (int j = 0; j < V; j++) {
      if (distances[j] != prev_distances[j]) {
        same = false;
        break;
      }
    }

    if (same)
      break;
  }

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


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
#define MIN(a, b) ((a < b) ? a : b)
#define INF 1000000001
#define N 100000

using namespace std;

struct edge {
  int source;
  int target;
  int weight;
};

vector<edge> edges;

int distances[100000];

int main() {
  int V, E, r;

  cin >> V >> E >> r;

  for (int i = 0; i < E; i++) {
    int source, target, distance;
    cin >> source >> target >> distance;
    edge new_edge = {source, target, distance};
    edges.push_back(new_edge);
  }

  // initialize distances array

  for (int i = 0; i < N; i++) {
    distances[i] = INF; // max value
  }

  distances[r] = 0;

  for (int i = 1; i < V; i++) {
    for (vector<edge>::iterator edgeptr = edges.begin(); edgeptr != edges.end();
         edgeptr++) {
      distances[edgeptr->target] =
          MIN(distances[edgeptr->source] + edgeptr->weight,
              distances[edgeptr->target]);
    }
  }

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

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define P pair<int, int>
int V, E;
struct edge {
  int to, cost;
};
vector<edge> G[110000];
int ans[110000];
const int INF = pow(2, 30);
int main() {
  fill(ans, ans + 100000, INF);
  int r;
  cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    edge tmp;
    tmp.to = t, tmp.cost = d;
    G[s].push_back(tmp);
  }
  ans[r] = 0;
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(make_pair(0, r)); // 距離、番号
  while (true) {
    if (que.size() == 0)
      break;
    // for(int i=0;i<V;i++)cout<<ans[i]<<" ";cout<<" ";
    P tmp =
        que.top(); // ここで使われていないものの中で最も距離が小さい頂点vの番号を求める
    que.pop();
    // cout<<tmp.first<<" "<<tmp.second<<endl;
    int v = tmp.second;
    // if(ans[v]<tmp.first)cout<<ans[v]<<" "<<tmp.first<<" "<<tmp.second<<endl;;
    if (ans[v] < tmp.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      if (ans[G[v][i].to] > ans[v] + G[v][i].cost) {
        ans[G[v][i].to] = ans[v] + G[v][i].cost;
        que.push(P(ans[G[v][i].to], G[v][i].to));
      }
    }
  }
  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 <cmath>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define P pair<int, int>
int V, E;
struct edge {
  int to, cost;
};
vector<edge> G[110000];
int ans[110000];
const int INF = pow(2, 30);
int main() {
  fill(ans, ans + 100000, INF);
  int r;
  cin >> V >> E >> r;
  for (int i = 0; i < E; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    edge tmp;
    tmp.to = t, tmp.cost = d;
    G[s].push_back(tmp);
  }
  ans[r] = 0;
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(make_pair(0, r)); // 距離、番号
  while (true) {
    if (que.size() == 0)
      break;
    // for(int i=0;i<V;i++)cout<<ans[i]<<" ";cout<<" ";
    P tmp =
        que.top(); // ここで使われていないものの中で最も距離が小さい頂点vの番号を求める
    que.pop();
    // cout<<tmp.first<<" "<<tmp.second<<endl;
    int v = tmp.second;
    for (int i = 0; i < G[v].size(); i++) {
      if (ans[G[v][i].to] > ans[v] + G[v][i].cost) {
        ans[G[v][i].to] = ans[v] + G[v][i].cost;
        que.push(make_pair(ans[i], G[v][i].to));
      }
    }
  }
  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

#include <iostream>
#define MAX_V 100000
#define MAX_E 500000
#define INF 1e9
using namespace std;
struct edge {
  int from, to, cost;
};
edge es[MAX_E];
int d[MAX_V];
int V;
int E;

bool find_negative_loop(int s) {
  d[s] = 0;
  int count = 0;
  while (true) {
    bool update = false;
    count++;
    for (int i = 0; i < MAX_E; i++) {

      if (d[es[i].from] != INF && d[es[i].to] > d[es[i].from] + es[i].cost) {
        if (count == V) {
          return true;
        }
        d[es[i].to] = d[es[i].from] + es[i].cost;
        update = true;
      }
    }
    if (update == false) {
      break;
    }
  }
  return false;
}

int main() {

  int r;
  cin >> V >> E >> r;
  for (int i = 0; i < MAX_V; i++) {
    d[i] = INF;
  }
  for (int i = 0; i < E; i++) {
    cin >> es[i].from >> es[i].to >> es[i].cost;
  }
  if (find_negative_loop(r)) {
    cout << "NEGATIVE CYCLE" << endl;
  } else {
    for (int i = 0; i < V; i++) {
      if (d[i] == INF) {
        cout << "INF" << endl;
      } else {
        cout << d[i] << endl;
      }
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#define MAX_V 1000
#define MAX_E 2000
#define INF 1e9
using namespace std;
struct edge {
  int from, to, cost;
};
edge es[MAX_E];
int d[MAX_V];
int V;
int E;

bool find_negative_loop(int s) {
  d[s] = 0;
  int count = 0;
  while (true) {
    bool update = false;
    count++;
    for (int i = 0; i < MAX_E; i++) {

      if (d[es[i].from] != INF && d[es[i].to] > d[es[i].from] + es[i].cost) {
        if (count == V) {
          return true;
        }
        d[es[i].to] = d[es[i].from] + es[i].cost;
        update = true;
      }
    }
    if (update == false) {
      break;
    }
  }
  return false;
}

int main() {

  int r;
  cin >> V >> E >> r;
  for (int i = 0; i < MAX_V; i++) {
    d[i] = INF;
  }
  for (int i = 0; i < E; i++) {
    cin >> es[i].from >> es[i].to >> es[i].cost;
  }
  if (find_negative_loop(r)) {
    cout << "NEGATIVE CYCLE" << endl;
  } else {
    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 <queue>
#include <stdio.h>
#include <vector>
using namespace std;
#define MAX_V 100001
#define INF (1e9 + 1)

int V, E, r, a, b, c;
vector<int> G_t[MAX_V];
vector<int> G_c[MAX_V];

int d[MAX_V];
void dijkstra() {
  int i;
  for (i = 0; i < MAX_V; i++)
    d[i] = INF;
  d[r] = 0;
  priority_queue<pair<int, int>> Q;
  Q.push(make_pair(-d[r], r));
  while (!Q.empty()) {
    pair<int, int> p = Q.top();
    Q.pop();
    int pos = p.second, cost = -p.first;
    if (cost > d[pos])
      continue;
    for (i = 0; i < G_t[pos].size(); i++) {
      int to = G_t[pos][i];
      int newcost = cost + G_c[pos][i];
      if (newcost < d[to]) {
        d[to] = newcost;
        Q.push(make_pair(-d[to], to));
      }
    }
  }
  for (i = 0; i < V; i++) {
    if (d[i] == INF)
      printf("INF\\n");
    else
      printf("%d\\n", d[i]);
  }
}
int main() {
  int i;
  scanf("%d%d%d", &V, &E, &r);
  for (i = 0; i < E; i++) {
    scanf("%d%d%d", &a, &b, &c);
    G_t[a].push_back(b);
    G_c[a].push_back(c);
  }
  dijkstra();
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
#define MAX_V 100001
#define INF (1e9 + 1)

int V, E, r, a, b, c;
vector<int> G_t[MAX_V];
vector<int> G_c[MAX_V];

int d[MAX_V];
void dijkstra() {
  int i;
  for (i = 0; i < MAX_V; i++)
    d[i] = INF;
  d[r] = 0;
  priority_queue<pair<int, int>> Q;
  Q.push(make_pair(-d[r], r));
  while (!Q.empty()) {
    pair<int, int> p = Q.top();
    Q.top();
    int pos = p.second, cost = -p.first;
    if (cost > d[pos])
      continue;
    for (i = 0; i < G_t[pos].size(); i++) {
      int to = G_t[pos][i];
      int newcost = cost + G_c[pos][i];
      if (newcost < d[to]) {
        d[to] = newcost;
        Q.push(make_pair(-d[to], to));
      }
    }
  }
  for (i = 0; i < V; i++) {
    if (d[i] == INF)
      printf("INF\\n");
    else
      printf("%d\\n", d[i]);
  }
}
int main() {
  int i;
  scanf("%d%d%d", &V, &E, &r);
  for (i = 0; i < E; i++) {
    scanf("%d%d%d", &a, &b, &c);
    G_t[a].push_back(b);
    G_c[a].push_back(c);
  }
  dijkstra();
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Time Limit Exceeded

/**
 * GRL_1-A - Shortest Path - Single Source Shortest Path
 */

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

using namespace std;
using ULL = unsigned long long;

const ULL INF = 1UL << 63;

struct edge {
  int to;
  ULL cost;
};

typedef pair<ULL, int> P;

int main() {

  int V, E, r;
  cin >> V >> E >> r;

  vector<edge> G[V];
  ULL cost[V];

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

  fill(cost, cost + V, INF);
  cost[r] = 0;

  priority_queue<P, vector<P>, greater<P>> pq;
  pq.push(make_pair(0, r));

  while (!pq.empty()) {

    P p = pq.top();
    pq.pop();

    if (p.first > cost[p.second])
      continue;

    for (edge e : G[p.second]) {
      if (p.first + e.cost < cost[e.to]) {
        cost[e.to] = p.first + e.cost;
        pq.push(P(cost[e.to], e.to));
      }
    }
  }

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


Error: TLE

Fixed submission:

/**
 * GRL_1-A - Shortest Path - Single Source Shortest Path
 */

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

using namespace std;
using ULL = unsigned long long;

const ULL INF = 1L << 63;

struct edge {
  int to;
  ULL cost;
};

int main() {

  int V, E, r;
  cin >> V >> E >> r;

  vector<edge> G[V];
  ULL cost[V];

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

  fill(cost, cost + V, INF);

  priority_queue<pair<ULL, int>> pq;
  pq.push(make_pair(0, r));

  while (!pq.empty()) {

    pair<ULL, int> p = pq.top();
    pq.pop();

    if (p.first > cost[p.second])
      continue;

    cost[p.second] = p.first;

    for (edge e : G[p.second]) {
      if (p.first + e.cost < cost[e.to]) {
        pq.push(make_pair(p.first + e.cost, e.to));
      }
    }
  }

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

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

#define ll long long int
#define P pair<ll, ll>

const ll INF = 10000000000;
struct edge {
  ll to, cost;
};

int v;
vector<edge> g[100000];
ll d[100000];

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();
    ll k = p.second;
    if (d[k] < p.first) {
      continue;
    }
    for (int i = 0; i < g[k].size(); i++) {
      edge e = g[k][i];
      if (d[e.to] > d[k] + e.cost) {
        d[e.to] = d[k] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {

  int e, r, s, t, l;

  cin >> v >> e >> r;

  for (int i = 0; i < e; i++) {
    cin >> s >> t >> l;
    edge ed;
    ed.to = t;
    ed.cost = l;
    g[s].push_back(ed);
  }

  dijkstra(r);

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

  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
using namespace std;

#define ll long long int

const ll INF = 1000000000000;

ll table[10000][10000];

int main() {

  ll v, e, r, s, t, d;

  cin >> v >> e >> r;

  for (ll i = 0; i < v; i++) {
    for (ll j = 0; j < v; j++) {
      table[i][j] = INF;
    }
  }

  for (ll i = 0; i < e; i++) {
    cin >> s >> t >> d;
    table[s][t] = d;
  }

  for (ll i = 0; i < v; i++) {
    table[i][i] = 0;
  }

  for (ll i = 0; i < v; i++) {
    for (ll j = 0; j < v; j++) {
      for (ll k = 0; k < v; k++) {
        table[j][k] = min(table[j][k], table[j][i] + table[i][k]);
      }
    }
  }
  /*
      for(int i=0;i<v;i++){
          for(int j=0;j<v;j++){
              cout << table[i][j] << " ";
          }
          cout << endl;
      }
  */
  for (ll i = 0; i < v; i++) {
    if (table[r][i] == INF) {
      cout << "INF" << endl;
    } else {
      cout << table[r][i] << endl;
    }
  }
  return 0;
}
Problem p02361 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 100005;

struct edge {
  int to, cost;
};

int n, m, s, cnt[maxn];
int d[maxn];
int qh, qt, q[maxn];
bool ok = 1, inq[maxn];
vector<edge> G[maxn];

int main() {
  cin >> n >> m >> s;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u].pb(edge{v, w});
  }
  memset(d, 0x3f, sizeof(d));
  d[s] = 0;
  q[qt++] = s;
  inq[s] = 1;
  while (qh != qt) {
    int u = q[qh++];
    if (qh >= maxn)
      qh = 0;
    inq[u] = 0;
    for (edge e : G[u]) {
      if (d[e.to] > d[u] + e.cost) {
        d[e.to] = d[u] + e.cost;
        if (!inq[e.to]) {
          q[qt++] = e.to;
          if (qt >= maxn)
            qt = 0;
          inq[e.to] = 1;
          ++cnt[e.to];
          if (cnt[u] > m + 5) {
            ok = 0;
            break;
          }
        }
      }
    }
    if (!ok)
      break;
  }
  if (!ok) {
    cout << "NEGATIVE CYCLE" << '\\n';
    return 0;
  } else
    for (int i = 0; i < n; i++)
      if (d[i] == INF)
        cout << "INF" << '\\n';
      else
        cout << d[i] << '\\n';
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1005;

struct edge {
  int to, cost;
};

int n, m, s, cnt[maxn];
int d[maxn];
int qh, qt, q[maxn * maxn];
bool ok = 1, inq[maxn];
vector<edge> G[maxn];

int main() {
  cin >> n >> m >> s;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u].pb(edge{v, w});
  }
  memset(d, 0x3f, sizeof(d));
  d[s] = 0;
  q[qt++] = s;
  inq[s] = 1;
  while (qh < qt) {
    int u = q[qh++];
    inq[u] = 0;
    for (edge e : G[u]) {
      if (d[e.to] > d[u] + e.cost) {
        d[e.to] = d[u] + e.cost;
        if (!inq[e.to]) {
          q[qt++] = e.to;
          inq[e.to] = 1;
          ++cnt[e.to];
          if (cnt[u] > m + 5) {
            ok = 0;
            break;
          }
        }
      }
    }
    if (!ok)
      break;
  }
  if (!ok) {
    cout << "NEGATIVE CYCLE" << '\\n';
    return 0;
  } else
    for (int i = 0; i < n; i++)
      if (d[i] == INF)
        cout << "INF" << '\\n';
      else
        cout << d[i] << '\\n';
}
Problem p02361 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

#define NOT -1
#define VMAX 100000

int main(void) {

  int V, E, r;
  int s, t, d;
  int v[VMAX];
  vector<int> ed[VMAX];
  vector<int> edco[VMAX];
  queue<int> no;

  cin >> V >> E >> r;

  for (int i = 0; i < V; i++)
    v[i] = NOT;

  for (int i = 0; i < E; i++) {
    cin >> s >> t >> d;
    ed[s].push_back(t);
    edco[s].push_back(d);
  }

  no.push(r);
  v[r] = 0;
  while (!no.empty()) {
    for (int i = 0; i < ed[no.front()].size(); i++) {
      if (v[no.front()] + edco[no.front()][i] < v[ed[no.front()][i]] ||
          v[ed[no.front()][i]] == NOT) {
        v[ed[no.front()][i]] = v[no.front()] + edco[no.front()][i];
        no.push(ed[no.front()][i]);
      }
    }
    no.pop();
  }

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

Error: -11

Fixed submission:

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

using namespace std;

#define NOT -1
#define VMAX 100000

int main(void) {

  int V, E, r;
  int s, t, d;
  int v[VMAX], ed[VMAX][VMAX];
  queue<int> no;

  cin >> V >> E >> r;

  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      ed[i][j] = NOT;
    }
  }
  for (int i = 0; i < V; i++)
    v[i] = NOT;

  for (int i = 0; i < E; i++) {
    cin >> s >> t >> d;
    ed[s][t] = d;
  }

  no.push(r);
  v[r] = 0;
  while (!no.empty()) {
    for (int i = 0; i < V; i++) {
      if (ed[no.front()][i] != NOT) {
        if (v[no.front()] + ed[no.front()][i] < v[i] || v[i] == NOT) {
          v[i] = v[no.front()] + ed[no.front()][i];
          no.push(i);
        }
      }
    }
    no.pop();
  }

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