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

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

#define CIN_ONLY if (1)
struct cww {
  cww() {
    CIN_ONLY {
      ios::sync_with_stdio(false);
      cin.tie(0);
    }
  }
} star;
#define fin "\\n"
#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if (0)
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
template <typename T> inline void chmin(T &l, T r) { l = min(l, r); }
template <typename T> inline void chmax(T &l, T r) { l = max(l, r); }
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &it : v)
    is >> it;
  return is;
}
typedef tuple<int, int, int, LL> T;
const LL INF = 1e15;
LL a[212345];
LL b[212345];
LL c[212345];
LL t[212345];

int main() {
  int N, M, S, G;
  cin >> N >> M >> S >> G;
  priority_queue<T> sc;
  vector<LL> ame(N + 1, INF);
  REP(i, M) {
    cin >> a[i] >> b[i] >> t[i] >> c[i];
    sc.push(T(-t[i], 0, i, 0));
  }
  ame[S] = 0;
  LL res = INF;
  while (sc.size()) {
    int tt, type, e;
    LL cww;
    tie(tt, type, e, cww) = sc.top();
    sc.pop();
    LL bg = t[e];
    LL ed = t[e] + c[e];
    if (type == 0) {
      LL cost = ame[a[e]] + t[e];
      sc.push(T(-ed, 1, e, cost));
    } else {
      if (b[e] == G)
        chmin(res, cww);
      chmin(ame[b[e]], cww - t[e] - c[e]);
    }
  }
  cout << res << endl;
  return 0;
}

Error: 0

Fixed submission:

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

#define CIN_ONLY if (1)
struct cww {
  cww() {
    CIN_ONLY {
      ios::sync_with_stdio(false);
      cin.tie(0);
    }
  }
} star;
#define fin "\\n"
#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if (0)
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
template <typename T> inline void chmin(T &l, T r) { l = min(l, r); }
template <typename T> inline void chmax(T &l, T r) { l = max(l, r); }
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  for (auto &it : v)
    is >> it;
  return is;
}
typedef tuple<int, int, int, LL> T;
const LL INF = 1e15;
LL a[112345];
LL b[112345];
LL c[112345];
LL t[112345];

int main() {
  int N, M, S, G;
  cin >> N >> M >> S >> G;
  priority_queue<T> sc;
  vector<LL> ame(N + 1, INF);
  REP(i, M) {
    cin >> a[i] >> b[i] >> t[i] >> c[i];
    sc.push(T(-t[i], 0, i, 0));
  }
  ame[S] = 0;
  LL res = INF;
  while (sc.size()) {
    int tt, type, e;
    LL cww;
    tie(tt, type, e, cww) = sc.top();
    sc.pop();
    LL bg = t[e];
    LL ed = t[e] + c[e];
    if (type == 0) {
      LL cost = ame[a[e]] + t[e];
      sc.push(T(-ed, 1, e, cost));
    } else {
      if (b[e] == G)
        chmin(res, cww);
      chmin(ame[b[e]], cww - t[e] - c[e]);
    }
  }
  cout << res << endl;
  return 0;
}
Problem p01911 (C++) — buggy submission, verdict: Time Limit Exceeded

/* attention to overflow */
#include <bits/stdc++.h>

#define dump(x) cerr << #x << " = " << x << endl
#define ALL(container) (container).begin(), (container).end()

using namespace std;
const int INF = 1 << 25;
void io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &s) {
  return os << '(' << s.first << ',' << s.second << ')';
}
/*printf("%.9Lf\\n",cf);*/
const int MOD = 1000000007;
const double EPS = 1e-8;

int dp[200010];
struct ed {
  int u, v, t, c;
};
vector<ed> eds(200010);
struct edge {
  int no, u, tc;
};
vector<edge> Graph[100010];

int N, M, S, G;

int memo(int q) {
  if (dp[q] != -1)
    return dp[q];

  int uofq = eds[q].u;
  int tofq = eds[q].t;

  if (uofq == S)
    return dp[q] = tofq;

  int tmp = INF;
  for (int i = 0; i < Graph[uofq].size(); i++) {
    int no = Graph[uofq][i].no;
    int tc = Graph[uofq][i].tc;
    // if(tc>tofq) continue;
    if (tc > tofq)
      break;
    tmp = min(tmp, (tofq - tc) + memo(no));
  }
  return dp[q] = tmp;
}

int main() {
  io();
  cin >> N >> M >> S >> G;
  S--, G--;
  fill_n(dp, M + 10, -1);
  for (int i = 0; i < M; i++) {
    int u, v, t, c;
    cin >> u >> v >> t >> c;
    u--, v--;
    Graph[v].push_back({i, u, t + c});

    // eds.push_back({u,v,t,c});
    eds[i] = {u, v, t, c};
  }

  for (int i = 0; i < N; i++) {
    sort(Graph[i].begin(), Graph[i].end(),
         [](const edge &a, const edge &b) { return a.tc < b.tc; });
  }

  int ans = INF;
  for (int i = 0; i < M; i++) {
    if (eds[i].v == G)
      ans = min(ans, memo(i));
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

/* attention to overflow */
#include <bits/stdc++.h>

#define dump(x) cerr << #x << " = " << x << endl
#define ALL(container) (container).begin(), (container).end()

using namespace std;
const int INF = 1 << 25;
void io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &s) {
  return os << '(' << s.first << ',' << s.second << ')';
}
/*printf("%.9Lf\\n",cf);*/
const int MOD = 1000000007;
const double EPS = 1e-8;

int dp[200010];
struct ed {
  int u, v, t, c;
};
vector<ed> eds(200010);
struct edge {
  int no, u, tc;
};
vector<edge> Graph[100010];

int N, M, S, G;

int memo(int q) {
  if (dp[q] != -1)
    return dp[q];

  int uofq = eds[q].u;
  int tofq = eds[q].t;

  if (uofq == S)
    return dp[q] = tofq;

  int tmp = INF;
  for (int i = 0; i < Graph[uofq].size(); i++) {
    int no = Graph[uofq][i].no;
    int tc = Graph[uofq][i].tc;
    if (tc > tofq)
      continue;
    tmp = min(tmp, (tofq - tc) + memo(no));
  }
  return dp[q] = tmp;
}

int main() {
  cin >> N >> M >> S >> G;
  S--, G--;
  fill_n(dp, M + 10, -1);
  for (int i = 0; i < M; i++) {
    int u, v, t, c;
    cin >> u >> v >> t >> c;
    u--, v--;
    Graph[v].push_back({i, u, t + c});

    // eds.push_back({u,v,t,c});
    eds[i] = {u, v, t, c};
  }

  int ans = INF;
  for (int i = 0; i < M; i++) {
    if (eds[i].v == G)
      ans = min(ans, memo(i));
  }
  cout << ans << endl;

  return 0;
}
Problem p01912 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int h, w, n;
int G[250001][22];
bool used[22][250001];

bool C(int v) {
  for (int i = 0; i < 20; i++) {
    memset(used[i + 1], false, sizeof(used[i + 1]));
    if ((v >> i) & 1) {
      for (int j = 0; j < w * h; j++) {
        if (used[i][j]) {
          if (used[i + 1][G[j][i]])
            return true;
          used[i + 1][G[j][i]] = true;
        }
      }
    } else {
      for (int j = 0; j < w * h; j++) {
        used[i + 1][j] = used[i][j];
      }
    }
  }
  return false;
}

int main(void) {
  scanf("%d%d%d", &h, &w, &n);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int r, c;
      scanf("%d%d", &r, &c);
      G[i * w + j][0] = r * w + c;
    }
  }
  for (int i = 0; i < n; i++) {
    int r, c;
    scanf("%d%d", &r, &c);
    used[0][r * w + c] = true;
  }
  for (int i = 1; i < 20; i++) {
    for (int j = 0; j < h * w; j++) {
      G[j][i] = G[G[j][i - 1]][i - 1];
    }
  }
  int l = 0, r = h * w + 1;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (C(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%d\\n", r == h * w + 1 ? -1 : r);
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int h, w, n;
int G[25001][22];
bool used[22][25001];

bool C(int v) {
  for (int i = 0; i < 20; i++) {
    memset(used[i + 1], false, sizeof(used[i + 1]));
    if ((v >> i) & 1) {
      for (int j = 0; j < w * h; j++) {
        if (used[i][j]) {
          if (used[i + 1][G[j][i]])
            return true;
          used[i + 1][G[j][i]] = true;
        }
      }
    } else {
      for (int j = 0; j < w * h; j++) {
        used[i + 1][j] = used[i][j];
      }
    }
  }
  return false;
}

int main(void) {
  scanf("%d%d%d", &h, &w, &n);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int r, c;
      scanf("%d%d", &r, &c);
      G[i * w + j][0] = r * w + c;
    }
  }
  for (int i = 0; i < n; i++) {
    int r, c;
    scanf("%d%d", &r, &c);
    used[0][r * w + c] = true;
  }
  for (int i = 1; i < 20; i++) {
    for (int j = 0; j < h * w; j++) {
      G[j][i] = G[G[j][i - 1]][i - 1];
    }
  }
  int l = 0, r = h * w + 1;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (C(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%d\\n", r == h * w + 1 ? -1 : r);
  return 0;
}
Problem p01913 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long int64;
const int64 INF = 1LL << 55;

int N, M, T;
int x[200000], y[200000], z[200000];
vector<pair<int, int>> g[200000];
int64 v[200000];

struct UnionFind {
  vector<int64> data, time, score;

  UnionFind(int sz) {
    data.assign(sz, -1LL);
    time.assign(sz, T);
    score.resize(sz);
    for (int i = 0; i < sz; i++) {
      if (v[i] == INF)
        score[i] = -INF;
      else
        score[i] = 0;
    }
  }

  int64 find(int64 k) {
    if (data[k] < 0)
      return (k);
    return (data[k] = find(data[k]));
  }

  void unite(int64 x, int64 y, int64 z) {
    x = find(x), y = find(y);
    if (x == y)
      return;
    score[x] = max(score[x] + size(x) * (time[x] - z),
                   score[y] + size(y) * (time[y] - z));
    data[x] += data[y];
    data[y] = x;
    time[x] = z;
  }

  int64 size(int64 k) { return (-data[find(k)]); }

  int64 res() { return (score[find(0)] + size(0) * time[find(0)]); }
};

int main() {
  cin >> N >> M >> T;
  for (int i = 0; i < M; i++) {
    cin >> x[i] >> y[i] >> z[i];
    --x[i], --y[i];
    g[x[i]].emplace_back(y[i], z[i]);
    g[y[i]].emplace_back(x[i], z[i]);
  }

  fill_n(v, 100000, INF);
  queue<int> que;
  que.push(0);
  v[0] = 0;
  while (!que.empty()) {
    int p = que.front();
    que.pop();
    for (auto &e : g[p]) {
      if (v[e.first] != INF || v[p] >= e.second)
        continue;
      v[e.first] = v[p] + 1;
      que.emplace(e.first);
    }
  }

  vector<int> to(M);
  iota(begin(to), end(to), 0);
  sort(begin(to), end(to), [&](int a, int b) { return (z[a] > z[b]); });
  UnionFind tree(N);
  for (int i : to)
    tree.unite(x[i], y[i], z[i]);
  cout << tree.res() << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long int64;

int N, M, T;
int x[200000], y[200000], z[200000];

struct UnionFind {
  vector<int64> data, time, score;

  UnionFind(int sz) {
    data.assign(sz, -1LL);
    time.assign(sz, T);
    score.assign(sz, 0LL);
  }

  int64 find(int64 k) {
    if (data[k] < 0)
      return (k);
    return (data[k] = find(data[k]));
  }

  void unite(int64 x, int64 y, int64 z) {
    x = find(x), y = find(y);
    if (x == y)
      return;
    if (data[x] > data[y])
      swap(x, y);
    score[x] = max(score[x] + size(x) * (time[x] - z),
                   score[y] + size(y) * (time[y] - z));
    data[x] += data[y];
    data[y] = x;
    time[x] = z;
  }

  int64 size(int64 k) { return (-data[find(k)]); }

  int64 res() { return (score[find(0)] + size(0) * time[find(0)]); }
};

int main() {
  cin >> N >> M >> T;
  for (int i = 0; i < M; i++) {
    cin >> x[i] >> y[i] >> z[i];
    --x[i], --y[i];
  }

  vector<int> to(M);
  iota(begin(to), end(to), 0);
  sort(begin(to), end(to), [&](int a, int b) { return (z[a] >= z[b]); });
  UnionFind tree(N);
  for (int i : to)
    tree.unite(x[i], y[i], z[i]);
  cout << tree.res() << endl;
}
Problem p01917 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int d[3][210];
int r[110], n;

bool f(int c) {
  vector<P> sc(n);
  int score[3][210] = {};
  rep(i, 0, 3) {
    vector<int> tmp(n);
    rep(j, 0, n) { tmp[j] = d[i][j]; }
    sort(tmp.begin(), tmp.end());
    reverse(tmp.begin(), tmp.end());
    int now = -1;
    int rank = -1;
    rep(j, 0, n) {
      if (tmp[j] != now) {
        now = tmp[j];
        rank = j;
      }
      score[i][tmp[j]] = r[rank];
    }
    // rep(j, 0, 100){
    //     cout << score[i][j] << " ";
    // }
    // cout << endl;
  }
  vector<P> sum(n);
  rep(i, 0, n) {
    sum[i].se = i;
    rep(j, 0, 3) { sum[i].fi -= score[j][d[j][i]]; }
  }
  sort(sum.begin(), sum.end());
  // rep(i, 0, n){
  //     cout << sum[i].se << " " << sum[i].fi << " " << endl;
  // }
  // cout << endl;
  rep(i, 0, 8) {
    if (sum[i].se == 0)
      return true;
  }
  return false;
}

int main() {
  cin >> n;
  rep(i, 0, n) cin >> r[i];
  rep(i, 0, n) {
    rep(j, 0, 3) { cin >> d[j][i]; }
  }

  rep(i, 0, 100) {
    rep(j, 0, 3) {
      d[j][0] += i;
      if (d[j][0] > 201)
        continue;
      if (f(j)) {
        cout << i << endl;
        return 0;
      }
      d[j][0] -= i;
      // if(i == 3) return 0;
      // cout << endl;
    }
  }
  cout << "Saiko" << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int d[3][110];
int r[110], n;

bool f(int c) {
  vector<P> sc(n);
  int score[3][110] = {};
  rep(i, 0, 3) {
    vector<int> tmp(n);
    rep(j, 0, n) { tmp[j] = d[i][j]; }
    sort(tmp.begin(), tmp.end());
    reverse(tmp.begin(), tmp.end());
    int now = -1;
    int rank = -1;
    rep(j, 0, n) {
      if (tmp[j] != now) {
        now = tmp[j];
        rank = j;
      }
      score[i][tmp[j]] = r[rank];
    }
    // rep(j, 0, 100){
    //     cout << score[i][j] << " ";
    // }
    // cout << endl;
  }
  vector<P> sum(n);
  rep(i, 0, n) {
    sum[i].se = i;
    rep(j, 0, 3) { sum[i].fi -= score[j][d[j][i]]; }
  }
  sort(sum.begin(), sum.end());
  // rep(i, 0, n){
  //     cout << sum[i].se << " " << sum[i].fi << " " << endl;
  // }
  // cout << endl;
  rep(i, 0, 8) {
    if (sum[i].se == 0)
      return true;
  }
  return false;
}

int main() {
  cin >> n;
  rep(i, 0, n) cin >> r[i];
  rep(i, 0, n) {
    rep(j, 0, 3) { cin >> d[j][i]; }
  }

  rep(i, 0, 100) {
    rep(j, 0, 3) {
      d[j][0] += i;
      if (f(j)) {
        cout << i << endl;
        return 0;
      }
      d[j][0] -= i;
      // if(i == 3) return 0;
      // cout << endl;
    }
  }
  cout << "Saiko" << endl;
}
Problem p01917 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;
int n, score[101], a[101][3];

bool ch() {

  int t[101] = {}, x[101];
  r(i, 3) {
    int cnt = 0, pre, c2 = 0;
    memset(x, 0, sizeof(x));

    vector<P> v;

    r(j, n) v.push_back(P(a[j][i], j));

    sort(v.begin(), v.end(), greater<P>());

    r(k, n) {
      if (!k) {
        t[v[k].se] += score[cnt];
        pre = v[k].fi;
      } else {
        if (pre == v[k].fi) {
          c2++;
          t[v[k].se] += score[cnt];
        } else {
          pre = v[k].fi;
          cnt += c2 + 1;
          c2 = 0;
          t[v[k].se] += score[cnt];
        }
      }
    }
  }

  vector<P> v;

  r(j, n) v.push_back(P(t[j], j));

  sort(v.begin(), v.end(), greater<P>());
  int cnt = 0, c2 = 0, pre;
  r(i, n) {
    if (!i) {

      if (!v[i].se && cnt <= 7)
        return 1;

      pre = v[i].fi;
    } else {
      if (pre == v[i].fi) {
        if (!v[i].se && cnt <= 7)
          return 1;
        pre = v[i].fi;
        c2++;
      } else {
        cnt += c2 + 1;
        c2 = 0;
        if (!v[i].se && cnt <= 7)
          return 1;
        pre = v[i].fi;
      }
    }
  }
  return 0;
}

int main() {
  cin >> n;
  r(i, n) cin >> score[i];
  r(i, n) r(j, 3) cin >> a[i][j];
  r(i, 1000) r(j, 3) {
    a[0][j] += i;
    if (ch()) {
      cout << i << endl;
      return 0;
    }
    a[0][j] -= i;
  }
  cout << "Saiko" << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;
int n, score[101], a[101][3];

bool ch() {

  int t[10] = {}, x[10];
  r(i, 3) {
    int cnt = 0, pre, c2 = 0;
    memset(x, 0, sizeof(x));

    vector<P> v;

    r(j, n) v.push_back(P(a[j][i], j));

    sort(v.begin(), v.end(), greater<P>());

    r(k, n) {
      if (!k) {
        t[v[k].se] += score[cnt];
        pre = v[k].fi;
      } else {
        if (pre == v[k].fi) {
          c2++;
          t[v[k].se] += score[cnt];
        } else {
          pre = v[k].fi;
          cnt += c2 + 1;
          c2 = 0;
          t[v[k].se] += score[cnt];
        }
      }
    }
  }

  vector<P> v;

  r(j, n) v.push_back(P(t[j], j));

  sort(v.begin(), v.end(), greater<P>());
  int cnt = 0, c2 = 0, pre;
  r(i, n) {
    if (!i) {

      if (!v[i].se && cnt <= 7)
        return 1;

      pre = v[i].fi;
    } else {
      if (pre == v[i].fi) {
        if (!v[i].se && cnt <= 7)
          return 1;
        pre = v[i].fi;
        c2++;
      } else {
        cnt += c2 + 1;
        c2 = 0;
        if (!v[i].se && cnt <= 7)
          return 1;
        pre = v[i].fi;
      }
    }
  }
  return 0;
}

int main() {
  cin >> n;
  r(i, n) cin >> score[i];
  r(i, n) r(j, 3) cin >> a[i][j];
  r(i, 1000) r(j, 3) {
    a[0][j] += i;
    if (ch()) {
      cout << i << endl;
      return 0;
    }
    a[0][j] -= i;
  }
  cout << "Saiko" << endl;
}
Problem p01919 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
struct edge {
  int to;
  ll cost;
};
vector<edge> G[60000];
ll dp[60000];
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
    qu; // dp[],2*(n-1)*c+v

int a, b, c;
int nextv(int v) { return (a * v + b) % c; }

int main(void) {
  int n, m, v0;
  cin >> n >> m;
  vector<int> x(m), y(m);
  vector<ll> t(m);
  rep(i, m) {
    cin >> x[i] >> y[i] >> t[i];
    --x[i];
    --y[i];
  }
  cin >> v0 >> a >> b >> c;
  rep(i, m) rep(v, c) {
    G[x[i] * c + v].push_back({y[i] * c + nextv(v), t[i] * v});
    G[y[i] * c + v].push_back({x[i] * c + nextv(v), t[i] * v});
    G[((n - 1) * 2 - x[i]) * c + v].push_back(
        {((n - 1) * 2 - y[i]) * c + nextv(v), t[i] * v});
    G[((n - 1) * 2 - y[i]) * c + v].push_back(
        {((n - 1) * 2 - x[i]) * c + nextv(v), t[i] * v});
  }
  rep(i, 60000) dp[i] = LLONG_MAX;
  dp[v0] = 0;
  qu.push({0, v0});
  while (qu.size()) {
    pair<ll, int> u = qu.top();
    qu.pop();
    if (u.second / c == 2 * (n - 1)) {
      cout << dp[u.second] << endl;
      return 0;
    }
    if (dp[u.second] < u.first)
      continue;
    for (auto e : G[u.second]) {
      if (dp[e.to] > dp[u.second] + e.cost) {
        dp[e.to] = dp[u.second] + e.cost;
        qu.push({dp[e.to], e.to});
      }
    }
  }

  // ll res = LLONG_MAX;
  // rep(i,c){
  // 	res = min(res,dp[2*(n-1)*c+i]);
  // }
  // cout<<res<<endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define debug(x) cout << #x << ": " << x << endl
typedef long long ll;
struct edge {
  int to;
  ll cost;
};

vector<edge> G[60000];
ll dp[60000];
priority_queue<pair<ll, int>> qu; // dp,v

int a, b, c;

int nextv(int v) { return (a * v + b) % c; }

int main(void) {
  int n, m, v0;
  cin >> n >> m;
  vector<int> x(m), y(m);
  vector<ll> t(m);
  rep(i, m) {
    cin >> x[i] >> y[i] >> t[i];
    --x[i];
    --y[i];
  }
  cin >> v0 >> a >> b >> c;
  rep(i, m) rep(v, c) {
    G[x[i] * c + v].push_back({y[i] * c + nextv(v), t[i] * v});
    G[y[i] * c + v].push_back({x[i] * c + nextv(v), t[i] * v});
    G[((n - 1) * 2 - x[i]) * c + v].push_back(
        {((n - 1) * 2 - y[i]) * c + nextv(v), t[i] * v});
    G[((n - 1) * 2 - y[i]) * c + v].push_back(
        {((n - 1) * 2 - x[i]) * c + nextv(v), t[i] * v});
  }
  rep(i, 60000) dp[i] = LLONG_MAX;
  dp[v0] = 0;
  qu.push({0, v0});
  while (qu.size()) {
    pair<ll, int> u = qu.top();
    qu.pop();
    if (dp[u.second] < u.first)
      continue;
    for (auto e : G[u.second]) {
      if (dp[e.to] > dp[u.second] + e.cost) {
        dp[e.to] = dp[u.second] + e.cost;
        qu.push({dp[e.to], e.to});
      }
    }
  }
  ll res = LLONG_MAX;
  rep(i, c) { res = min(res, dp[2 * (n - 1) * c + i]); }
  cout << res << endl;

  return 0;
}
Problem p01919 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define N 501
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
ll const INF = 1LL << 55;
ll n, m;
vector<P> G[N];
ll v0, a, b, C;
ll v[5010];

int nv(ll v) { return (v * a + b) % C; }

ll dijkstra(ll start, ll goal, ll c) {
  ll D[500][100];
  for (ll i = 0; i < 500; i++)
    for (ll j = 0; j < 100; j++)
      D[i][j] = INF;

  priority_queue<PP, vector<PP>, greater<PP>> Q;
  Q.push(PP(0, P(start, c)));
  D[start][c] = 0;
  ll res = INF;
  while (!Q.empty()) {
    PP t = Q.top();
    Q.pop();
    ll cost = t.first;
    ll pos = t.second.first;
    ll v = t.second.second;
    if (D[pos][v] < cost)
      continue;
    if (pos == goal && goal == 0)
      return cost;
    if (pos == goal && goal == n - 1) {
      res = min(res, cost + dijkstra(n - 1, 0, v));
      continue;
    }

    for (ll i = 0; i < (ll)G[pos].size(); i++) {
      ll npos = G[pos][i].first;
      ll ncost = cost + v * G[pos][i].second;
      ll nV = nv(v);
      if (D[npos][nV] <= ncost)
        continue;
      Q.push(PP(ncost, P(npos, nV)));
      D[npos][nV] = ncost;
    }
  }
  return res;
}

int main() {
  cin >> n >> m;
  for (ll i = 0, x, y, t; i < m; i++) {
    cin >> x >> y >> t;
    x--, y--;
    G[x].push_back(P(y, t));
    G[y].push_back(P(x, t));
  }

  int v0;
  cin >> v0 >> a >> b >> C;
  cout << dijkstra(0, n - 1, v0) << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define N 501
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
ll const INF = 1LL << 60;
ll n, m;
vector<P> G[N];
ll v0, a, b, C;
ll v[50100];

ll nC;
ll dijkstra(ll start, ll goal, ll c) {
  ll D[500][5001];
  for (ll i = 0; i < 500; i++)
    for (ll j = 0; j < 5001; j++)
      D[i][j] = INF;

  priority_queue<PP, vector<PP>, greater<PP>> Q;
  Q.push(PP(0, P(start, c)));
  D[start][c] = 0;
  ll res = INF;
  while (!Q.empty()) {
    PP t = Q.top();
    Q.pop();
    ll cost = t.first;
    ll pos = t.second.first;
    ll cnt = t.second.second;
    if (D[pos][cnt] < cost)
      continue;
    if (pos == goal && goal == 0)
      return cost;
    if (pos == goal && goal == n - 1) {
      res = min(res, cost + dijkstra(n - 1, 0, cnt));
      continue;
    }
    for (ll i = 0; i < (ll)G[pos].size(); i++) {
      ll npos = G[pos][i].first;
      ll ncost = cost + v[cnt] * G[pos][i].second;
      ll ncnt = (cnt + 1) % nC;
      if (D[npos][ncnt] <= ncost)
        continue;
      Q.push(PP(ncost, P(npos, ncnt)));
      D[npos][ncnt] = ncost;
    }
  }
  return res;
}

int main() {
  cin >> n >> m;
  for (ll i = 0, x, y, t; i < m; i++) {
    cin >> x >> y >> t;
    x--, y--;
    G[x].push_back(P(y, t));
    G[y].push_back(P(x, t));
  }
  cin >> v[0] >> a >> b >> C;
  set<ll> S;
  S.insert(v[0]);
  for (ll i = 1;; i++) {
    v[i] = (a * v[i - 1] + b) % C;
    if (S.count(v[i]))
      break;
    S.insert(v[i]);
  }
  nC = S.size();
  cout << dijkstra(0, n - 1, 0) << endl;
  return 0;
}