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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll N;
  cin >> N;
  ll M;
  cin >> M;
  ll S;
  cin >> S;
  vector<ll> C(N), D(N);

  vector<pair<ll, pair<ll, ll>>> G[N]; // to, coin, time

  for (ll i = 0; i < M; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    G[u].push_back(make_pair(v, make_pair(a, b)));
    G[v].push_back(make_pair(u, make_pair(a, b)));
  }
  for (ll i = 0; i < N; i++) {
    cin >> C[i] >> D[i];
  }

  S = min(S, (ll)2500);
  ll INF = 1e18;
  vector<vector<ll>> dp(N, vector<ll>(2550, INF));
  queue<pair<ll, pair<ll, ll>>> q; // time, location, coin
  q.push(make_pair(0, make_pair(0, S)));
  while (!q.empty()) {
    pair<ll, pair<ll, ll>> c = q.front();
    q.pop();
    ll mins = c.first, loc = c.second.first, coin = c.second.second;
    if (dp[loc][coin] <= mins)
      continue;
    dp[loc][coin] = mins;

    for (auto n : G[loc]) {
      ll new_mins = mins + n.second.second;
      ll new_loc = n.first;
      ll new_coin = coin - n.second.first;
      if (new_coin < 0)
        continue;
      q.push(make_pair(new_mins, make_pair(new_loc, new_coin)));
    }

    ll new_mins = mins + D[loc];
    ll new_coin = coin + C[loc];
    if (new_coin > 2500)
      new_coin = 2500;
    q.push(make_pair(new_mins, make_pair(loc, new_coin)));
  }

  for (ll i = 1; i < N; i++) {
    ll ans = INF;
    for (ll j = 0; j < 2550; j++) {
      ans = min(ans, dp[i][j]);
    }
    cout << ans << '\\n';
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll N;
  cin >> N;
  ll M;
  cin >> M;
  ll S;
  cin >> S;
  vector<ll> C(N), D(N);

  vector<pair<ll, pair<ll, ll>>> G[N]; // to, coin, time

  for (ll i = 0; i < M; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    G[u].push_back(make_pair(v, make_pair(a, b)));
    G[v].push_back(make_pair(u, make_pair(a, b)));
  }
  for (ll i = 0; i < N; i++) {
    cin >> C[i] >> D[i];
  }

  ll INF = 1e18;
  vector<vector<ll>> dp(N, vector<ll>(2550, INF));
  queue<pair<ll, pair<ll, ll>>> q; // time, location, coin
  q.push(make_pair(0, make_pair(0, S)));
  while (!q.empty()) {
    pair<ll, pair<ll, ll>> c = q.front();
    q.pop();
    ll mins = c.first, loc = c.second.first, coin = c.second.second;
    if (dp[loc][coin] <= mins)
      continue;
    dp[loc][coin] = mins;

    for (auto n : G[loc]) {
      ll new_mins = mins + n.second.second;
      ll new_loc = n.first;
      ll new_coin = coin - n.second.first;
      if (new_coin < 0)
        continue;
      q.push(make_pair(new_mins, make_pair(new_loc, new_coin)));
    }

    ll new_mins = mins + D[loc];
    ll new_coin = coin + C[loc];
    if (new_coin > 2500)
      new_coin = 2500;
    q.push(make_pair(new_mins, make_pair(loc, new_coin)));
  }

  for (ll i = 1; i < N; i++) {
    ll ans = INF;
    for (ll j = 0; j < 2550; j++) {
      ans = min(ans, dp[i][j]);
    }
    cout << ans << '\\n';
  }
  return 0;
}
Problem p02703 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <vector>

#define LL long long
using namespace std;
#define MAXN 60
#define MAXA 60

int N, M, S;

struct edge {
  int v, a, b;
};
vector<edge> G[MAXN];
int C[MAXN], D[MAXN];
LL dp[MAXN][MAXA * MAXN];
LL ans[MAXN];

inline void add(int u, int v, int a, int b) {
  G[u].push_back({v, a, b});
  G[v].push_back({u, a, b});
}
int main() {
  scanf("%d%d%d", &N, &M, &S);
  int u, v, a, b;
  for (int i = 1; i <= M; i++) {
    scanf("%d%d%d%d", &u, &v, &a, &b);
    add(u, v, a, b);
  }
  for (int i = 1; i <= N; i++) {
    scanf("%d%d", &C[i], &D[i]);
  }

  memset(dp, 0x3f, sizeof(dp));
  memset(ans, 0x3f, sizeof(ans));

  if (S > 2500)
    S = 2500;
  dp[1][S] = 0;
  for (int t = 0; t <= N; t++) {
    for (int i = 1; i <= N; i++) {
      for (int k = 0; k < G[i].size(); k++) {
        for (int j = 0; j <= 2500; j++) {
          if (j + G[i][k].a <= 2500)
            dp[i][j] = min(dp[i][j], dp[G[i][k].v][j + G[i][k].a] + G[i][k].b);
          if (ans[i] > dp[i][j]) {
            ans[i] = dp[i][j];
          }
        }
      }

      for (int j = 0; j <= 2500; j++) {
        if (j >= C[i])
          dp[i][j] = min(dp[i][j], dp[i][j - C[i]] + D[i]);
        if (ans[i] > dp[i][j]) {
          ans[i] = dp[i][j];
        }
      }
    }
  }
  for (int i = 2; i <= N; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <vector>

#define LL long long
using namespace std;
#define MAXN 60
#define MAXA 60

int N, M, S;

struct edge {
  int v, a, b;
};
vector<edge> G[MAXN];
int C[MAXN], D[MAXN];
LL dp[MAXN][MAXA * MAXN];
LL ans[MAXN];

inline void add(int u, int v, int a, int b) {
  G[u].push_back({v, a, b});
  G[v].push_back({u, a, b});
}
int main() {
  scanf("%d%d%d", &N, &M, &S);
  int u, v, a, b;
  for (int i = 1; i <= M; i++) {
    scanf("%d%d%d%d", &u, &v, &a, &b);
    add(u, v, a, b);
  }
  for (int i = 1; i <= N; i++) {
    scanf("%d%d", &C[i], &D[i]);
  }

  memset(dp, 0x3f, sizeof(dp));
  memset(ans, 0x3f, sizeof(ans));

  dp[1][S] = 0;
  for (int t = 0; t < N; t++) {
    for (int i = 1; i <= N; i++) {
      for (int k = 0; k < G[i].size(); k++) {
        for (int j = 0; j <= 2500; j++) {
          dp[i][j] = min(dp[i][j], dp[G[i][k].v][j + G[i][k].a] + G[i][k].b);
        }
      }

      for (int j = 0; j <= 2500; j++) {
        if (j >= C[i])
          dp[i][j] = min(dp[i][j], dp[i][j - C[i]] + D[i]);
        if (ans[i] > dp[i][j]) {
          ans[i] = dp[i][j];
        }
      }
    }
  }
  for (int i = 2; i <= N; i++) {
    cout << ans[i] << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
ll ans[55], c[55], d[55], f[55][10005];
struct E {
  ll to, a, b;
};
struct P {
  ll t, pos, s;
};
bool operator<(const P &a, const P &b) { return a.t > b.t; }
vector<E> edge[55];
priority_queue<P> q;
int main() {
  ll n, m, k, sum = 0;
  cin >> n >> m >> k;
  for (ll i = 1; i <= m; i++) {
    ll u, v, x, y;
    cin >> u >> v >> x >> y;
    edge[u].push_back({v, x, y});
    edge[v].push_back({u, x, y});
  }
  for (ll i = 1; i <= n; i++) {
    cin >> c[i] >> d[i];
    c[i] = min(c[i], (ll)5000);
  }
  k = min(k, (ll)5000);
  q.push({1, 1, k});
  while (!q.empty() && sum < n) {
    ll x = q.top().t, p = q.top().pos, num = q.top().s;
    q.pop();
    if (f[p][num])
      continue;
    f[p][num] = x;
    if (!ans[p])
      ans[p] = x, sum++;
    for (E i : edge[p]) {
      if (i.a <= num && !f[i.to][num - i.a])
        q.push({x + i.b, i.to, num - i.a});
      if (num + c[p] <= 5000)
        q.push({x + d[p], p, num + c[p]});
    }
  }
  for (int i = 2; i <= n; i++) {
    cout << ans[i] - 1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
ll ans[55], c[55], d[55], f[55][10005];
struct E {
  ll to, a, b;
};
struct P {
  ll t, pos, s;
};
bool operator<(const P &a, const P &b) { return a.t > b.t; }
vector<E> edge[55];
priority_queue<P> q;
int main() {
  ll n, m, k, sum = 0;
  cin >> n >> m >> k;
  for (ll i = 1; i <= m; i++) {
    ll u, v, x, y;
    cin >> u >> v >> x >> y;
    edge[u].push_back({v, x, y});
    edge[v].push_back({u, x, y});
  }
  for (ll i = 1; i <= n; i++) {
    cin >> c[i] >> d[i];
    c[i] = min(c[i], (ll)5000);
  }
  k = min(k, (ll)5000);
  q.push({1, 1, k});
  f[1][k] = 1;
  while (!q.empty() && sum < n) {
    ll x = q.top().t, p = q.top().pos, num = q.top().s;
    q.pop();
    if (!ans[p])
      ans[p] = x, sum++;
    for (E i : edge[p]) {
      if (i.a <= num && !f[i.to][num - i.a])
        f[i.to][num - i.a] = x + i.b, q.push({x + i.b, i.to, num - i.a});
      if (num + c[p] <= 10000)
        q.push({x + d[p], p, num + c[p]});
    }
  }
  for (int i = 2; i <= n; i++) {
    cout << ans[i] - 1 << endl;
  }
}
Problem p02703 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int nm = 50, am = 50;
int n, m, s, r;
long long ans[nm], reach[nm][(nm - 1) * am + 1];
bool visited[nm];

struct Edge {
  int opp;
  int cost;
  int time;
  Edge(int o, int c, int t) : opp(o), cost(c), time(t) {}
};
vector<Edge> g[nm];

struct State {
  long long time;
  int num;
  int coin;
  State(long long t, int n, int c) : time(t), num(n), coin(c) {}
};
auto comp = [](State &a, State &b) { return a.time > b.time; };

priority_queue<State, vector<State>, decltype(comp)> q(comp);

int main() {
  cin >> n >> m >> s;
  fill(reach[0], reach[n], LLONG_MAX);
  s = min(s, (nm - 1) * am);
  r = n - 1;
  for (int i = 0, u, v, a, b; i < m; i++) {
    cin >> u >> v >> a >> b;
    u--, v--;
    g[u].emplace_back(v, a, b);
    g[v].emplace_back(u, a, b);
  }
  for (int i = 0, c, d; i < n; i++) {
    cin >> c >> d;
    g[i].emplace_back(i, -c, d);
  }
  visited[0] = 1;
  for (int i = 0; i <= s; i++)
    reach[0][i] = 0;
  q.emplace(0, 0, s);
  while (1) {
    long long t = q.top().time;
    int v = q.top().num;
    int c = q.top().coin;
    q.pop();
    if (!visited[v]) {
      visited[v] = 1;
      ans[v] = t;
      if (!--r)
        break;
    }
    for (Edge &e : g[v]) {
      if (e.cost > c)
        continue;
      long long nt = t + e.time;
      int nv = e.opp;
      int nc = min(c - e.cost, (nm - 1) * am);
      if (nt < reach[nv][nc]) {
        for (int i = 0; i <= nc; i++)
          reach[nv][i] = min(reach[nv][i], nt);
        q.emplace(nt, nv, nc);
      }
    }
  }
  for (int i = 1; i < n; i++)
    cout << ans[i] << endl;
}


Error: TLE

Fixed submission:

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

struct E {
  int n, a, b;
  E(int n0, int a0, int b0) {
    n = n0;
    a = a0;
    b = b0;
  }
};

struct O {
  long long t;
  int v;
  long long c;
  O() {
    t = 0;
    v = 0;
    c = 0;
  }
  O(long long t0, int v0, long long c0) {
    t = t0;
    v = v0;
    c = c0;
  }
};

const int nm = 50, mm = 100;
const auto comp = [](O x, O y) { return x.t > y.t; };
int n, m, s, r, c[nm], d[nm], am = 0;
long long t[nm];
bool b[nm] = {1};
vector<E> g[nm];

O o;

int main() {
  cin >> n >> m >> s;
  r = n - 1;
  for (int i = 0, u, v, a, b; i < m; i++) {
    cin >> u >> v >> a >> b;
    u--, v--;
    g[u].emplace_back(v, a, b);
    g[v].emplace_back(u, a, b);
    am = max(am, a);
  }
  for (int i = 0; i < n; i++)
    cin >> c[i] >> d[i];
  priority_queue<O, vector<O>, decltype(comp)> q(comp);
  q.emplace(0, 0, s);

  while (r) {
    o = q.top();
    q.pop();
    if (o.v)
      if (!b[o.v]) {
        b[o.v] = 1;
        t[o.v] = o.t;
        r--;
      }
    if (o.c + c[o.v] <= am * (n - 1))
      q.emplace(o.t + d[o.v], o.v, o.c + c[o.v]);
    for (E e : g[o.v])
      if (e.a <= o.c)
        q.emplace(o.t + e.b, e.n, o.c - e.a);
  }
  for (int i = 1; i < n; i++)
    cout << t[i] << endl;
}
Problem p02703 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
using namespace std;
struct edge {
  int v, n;
  long long w;
} e[2000005];
int head[500005], cnt;
long long dis[500005], ans[5005];
int vis[500005];
inline void add(int u, int v, long long w) {
  e[++cnt] = {v, head[u], w};
  head[u] = cnt;
}
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
               greater<pair<long long, int>>>
    q;
inline int id(int x, int y) { return x * 5001 + y; }
int main(int argc, char **argv) {
  int n, m, st;
  cin >> n >> m >> st;
  for (int i = 1; i <= m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    for (int j = a; j <= 5000; j++)
      add(id(u, j), id(v, j - a), b), add(id(v, j), id(u, j - a), b);
  }
  for (int i = 1; i <= n; i++) {
    int c, d;
    cin >> c >> d;
    for (int j = 0; j <= 5000; j++)
      add(id(i, j), id(i, min(5000, j + c)), d);
  }
  int s = id(1, min(st, 5000));
  q.push({0, s});
  for (int i = 1; i <= 500000; i++)
    dis[i] = 1e18;
  dis[s] = 0;
  while (!q.empty()) {
    int x = q.top().second;
    q.pop();
    if (vis[x])
      continue;
    vis[x] = 1;
    for (int i = head[x]; i; i = e[i].n) {
      if (dis[e[i].v] > dis[x] + e[i].w) {
        dis[e[i].v] = dis[x] + e[i].w;
        q.push({dis[e[i].v], e[i].v});
      }
    }
  }
  for (int i = 2; i <= n; i++) {
    ans[i] = 1e18;
    for (int j = 0; j <= 5000; j++)
      ans[i] = min(ans[i], dis[id(i, j)]);
    cout << ans[i] << "\\n";
  }
  //	for(int i=1;i<=n;i++)
  //		cout << dis[i] << " ";
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <queue>
using namespace std;
struct edge {
  int v, n;
  long long w;
} e[1000005];
int head[500005], cnt;
long long dis[500005], ans[5005];
int vis[500005];
inline void add(int u, int v, int w) {
  e[++cnt] = {v, head[u], w};
  head[u] = cnt;
}
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
               greater<pair<long long, int>>>
    q;
inline int id(int x, int y) { return x * 5001 + y; }
int main(int argc, char **argv) {
  int n, m, st;
  cin >> n >> m >> st;
  for (int i = 1; i <= m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    for (int j = a; j <= 5000; j++)
      add(id(u, j), id(v, j - a), b), add(id(v, j), id(u, j - a), b);
  }
  for (int i = 1; i <= n; i++) {
    int c, d;
    cin >> c >> d;
    for (int j = 0; j <= 5000; j++)
      add(id(i, j), id(i, min(5000, j + c)), d);
  }
  int s = id(1, min(st, 5000));
  q.push({0, s});
  for (int i = 1; i <= 300000; i++)
    dis[i] = 1e18;
  dis[s] = 0;
  while (!q.empty()) {
    int x = q.top().second;
    q.pop();
    if (vis[x])
      continue;
    vis[x] = 1;
    for (int i = head[x]; i; i = e[i].n) {
      if (dis[e[i].v] > dis[x] + e[i].w) {
        dis[e[i].v] = dis[x] + e[i].w;
        q.push({dis[e[i].v], e[i].v});
      }
    }
  }
  for (int i = 2; i <= n; i++) {
    ans[i] = 1e18;
    for (int j = 0; j <= 5000; j++)
      ans[i] = min(ans[i], dis[id(i, j)]);
    cout << ans[i] << "\\n";
  }
  //	for(int i=1;i<=n;i++)
  //		cout << dis[i] << " ";
  return 0;
}
Problem p02703 (C++) — buggy submission, verdict: Runtime Error

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

// @author: pashka

const int MAX = 2501;

struct edge {
  int dest;
  long time;
};

int main() {
  ios::sync_with_stdio(false);

  int n, m, s;
  cin >> n >> m >> s;

  s = min(s, MAX - 1);
  int nn = n * MAX;
  vector<vector<edge>> g(nn);

  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    for (int j = a; j < MAX; j++) {
      g[j * n + u].push_back({(j - a) * n + v, b});
      g[j * n + v].push_back({(j - a) * n + u, b});
    }
  }
  for (int i = 0; i < n; i++) {
    int c, d;
    cin >> c >> d;
    for (int j = 0; j < MAX; j++) {
      g[j * n + i].push_back({min(j + c, MAX - 1) * n + i, d});
    }
  }

  set<pair<int, int>> q;
  vector<long> d(nn, LLONG_MAX);
  s = s * n;
  d[s] = 0;
  q.insert({d[s], s});
  while (!q.empty()) {
    auto p = *q.begin();
    q.erase(p);
    int x = p.second;
    for (auto e : g[x]) {
      int y = e.dest;
      long dd = d[x] + e.time;
      if (dd < d[y]) {
        q.erase({d[y], y});
        d[y] = dd;
        q.insert({d[y], y});
      }
    }
  }
  for (int i = 1; i < n; i++) {
    long res = LLONG_MAX;
    for (int j = 0; j < MAX; j++) {
      res = min(res, d[j * n + i]);
    }
    cout << res << " ";
  }

  return 0;
}

Error: WA

Fixed submission:

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

// @author: pashka

const int MAX = 2501;

struct edge {
  int dest;
  long time;
};

int main() {
  ios::sync_with_stdio(false);

  int n, m, s;
  cin >> n >> m >> s;

  s = min(s, MAX - 1);
  int nn = n * MAX;
  vector<vector<edge>> g(nn);

  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    for (int j = a; j < MAX; j++) {
      g[j * n + u].push_back({(j - a) * n + v, b});
      g[j * n + v].push_back({(j - a) * n + u, b});
    }
  }
  for (int i = 0; i < n; i++) {
    int c, d;
    cin >> c >> d;
    for (int j = 0; j < MAX; j++) {
      g[j * n + i].push_back({min(j + c, MAX - 1) * n + i, d});
    }
  }

  set<pair<int, int>> q;
  vector<long> d(nn, LLONG_MAX);
  s = s * n;
  d[s] = 0;
  q.insert({d[s], s});
  while (!q.empty()) {
    auto p = *q.begin();
    q.erase(p);
    int x = p.second;
    for (auto e : g[x]) {
      int y = e.dest;
      long dd = d[x] + e.time;
      if (dd < d[y]) {
        q.erase({y, d[y]});
        d[y] = dd;
        q.insert({y, d[y]});
      }
    }
  }
  for (int i = 1; i < n; i++) {
    long res = LLONG_MAX;
    for (int j = 0; j < MAX; j++) {
      res = min(res, d[j * n + i]);
    }
    cout << res << " ";
  }

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

#include <bits/stdc++.h>
using namespace std;
long long n, m, dp[53][2503], s;
vector<pair<long long, pair<long long, long long>>> v[53];
int main() {
  scanf("%lld%lld%lld", &n, &m, &s);
  s = min(s, n * 50);
  while (m--) {
    long long x, y, a, b;
    scanf("%lld%lld%lld%lld", &x, &y, &a, &b);
    v[x - 1].push_back(make_pair(y - 1, make_pair(-a, b)));
    v[y - 1].push_back(make_pair(x - 1, make_pair(-a, b)));
  }
  memset(dp, 31, sizeof(dp));
  for (long long i = 0; i < n; i++) {
    long long c, d;
    cin >> c >> d;
    v[i].push_back(make_pair(i, make_pair(c, d)));
  }
  priority_queue<pair<long long, pair<long long, long long>>> Q;
  Q.push(make_pair(0, make_pair(0, s)));
  dp[0][s] = 0;
  while (Q.size()) {
    long long tm = Q.top().first, ct = Q.top().second.first,
              cn = Q.top().second.second;
    Q.pop();
    for (long long i = 0; i < v[ct].size(); i++) {
      long long nct = v[ct][i].first, ntm = tm - v[ct][i].second.second,
                ncoi = v[ct][i].second.first + cn;
      if (ncoi < 0)
        continue;
      if (ncoi > n * 50)
        continue;
      ncoi = min(ncoi, n * 50);
      if (dp[nct][ncoi] > -ntm) {
        dp[nct][ncoi] = -ntm;
        Q.push(make_pair(ntm, make_pair(nct, ncoi)));
      }
    }
  }
  for (long long i = 1; i < n; i++) {
    long long ans = LONG_LONG_MAX;
    for (long long j = 0; j <= n * 50; j++)
      ans = min(ans, dp[i][j]);
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, m, dp[53][2503], s;
vector<pair<long long, pair<long long, long long>>> v[53];
int main() {
  scanf("%lld%lld%lld", &n, &m, &s);
  s = min(s, n * 50);
  while (m--) {
    long long x, y, a, b;
    scanf("%lld%lld%lld%lld", &x, &y, &a, &b);
    v[x - 1].push_back(make_pair(y - 1, make_pair(-a, b)));
    v[y - 1].push_back(make_pair(x - 1, make_pair(-a, b)));
  }
  memset(dp, 31, sizeof(dp));
  for (long long i = 0; i < n; i++) {
    long long c, d;
    cin >> c >> d;
    v[i].push_back(make_pair(i, make_pair(c, d)));
  }
  priority_queue<pair<long long, pair<long long, long long>>> Q;
  Q.push(make_pair(0, make_pair(0, s)));
  dp[0][s] = 0;
  while (Q.size()) {
    long long tm = -Q.top().first, ct = Q.top().second.first,
              cn = Q.top().second.second;
    Q.pop();
    for (long long i = 0; i < v[ct].size(); i++) {
      long long nct = v[ct][i].first, ntm = tm - v[ct][i].second.second,
                ncoi = v[ct][i].second.first + cn;
      if (ncoi < 0)
        continue;
      if (ncoi > n * 50)
        continue;
      if (dp[nct][ncoi] <= -ntm)
        continue;
      dp[nct][ncoi] = -ntm;
      Q.push(make_pair(-ntm, make_pair(nct, ncoi)));
    }
  }
  for (long long i = 1; i < n; i++) {
    long long ans = LONG_LONG_MAX;
    for (long long j = 0; j <= n * 50; j++)
      ans = min(ans, dp[i][j]);
    cout << ans << endl;
  }
}
Problem p02703 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;

typedef pair<ll, pll> ppll;

int main() {
  ll n, m, s;
  cin >> n >> m >> s;
  vector<map<ll, pll>> G(n);
  for (ll i = 0; i < m; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    G[u][v] = {a, b};
    G[v][u] = {a, b};
  }
  vec mai(n), mnu(n);
  for (ll i = 0; i < n; i++) {
    cin >> mai[i] >> mnu[i];
  }
  mat d(n, vec(50 * (n - 1) + 1, -1));
  vec ans(n, -1);
  vec mins(n, -1);
  priority_queue<ppll, vector<ppll>, greater<ppll>> q;
  s = min(s, 50 * (n - 1));
  q.push({0, {0, s}});
  while (q.size()) {
    ll td = q.top().first;
    ll f = q.top().second.first;
    ll s = q.top().second.second;
    q.pop();
    ll flag = 0;
    if (ans[f] < 0)
      ans[f] = td;
    if (d[f][s] > -1)
      continue;
    d[f][s] = td;
    mins[f] = s;
    for (auto p : G[f]) {
      ll t = p.first;
      ll co = p.second.first;
      ll v = p.second.second;
      if (s - co >= 0 && d[t][s - co] == -1) {
        q.push({td + v, {t, s - co}});
      }
    }
    ll ns = min(s + mai[f], 50 * (n - 1));
    ll nd = td + mnu[f];
    if (d[f][ns] == -1)
      q.push({nd, {f, ns}});
  }
  for (ll i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;

typedef pair<ll, pll> ppll;

int main() {
  ll n, m, s;
  cin >> n >> m >> s;
  vector<map<ll, pll>> G(n);
  for (ll i = 0; i < m; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    G[u][v] = {a, b};
    G[v][u] = {a, b};
  }
  vec mai(n), mnu(n);
  for (ll i = 0; i < n; i++) {
    cin >> mai[i] >> mnu[i];
  }
  mat d(n, vec(50 * (n - 1) + 1, -1));
  vec ans(n, -1);
  vec mins(n, -1);
  priority_queue<ppll, vector<ppll>, greater<ppll>> q;
  s = min(s, 50 * (n - 1));
  q.push({0, {0, s}});
  while (q.size()) {
    ll td = q.top().first;
    ll f = q.top().second.first;
    ll s = q.top().second.second;
    q.pop();
    ll flag = 0;
    if (ans[f] < 0)
      ans[f] = td;
    if (d[f][s] > -1)
      continue;
    d[f][s] = td;
    mins[f] = s;
    for (auto p : G[f]) {
      ll t = p.first;
      ll co = p.second.first;
      ll v = p.second.second;
      if (s - co >= 0 && d[t][s - co] == -1) {
        q.push({td + v, {t, s - co}});
      }
    }
    for (ll i = 0; 1; i++) {
      ll ns = min(s + i * mai[f], 50 * (n - 1));
      ll nd = td + i * mnu[f];
      if (d[f][ns] == -1)
        q.push({nd, {f, ns}});
      if (ns == 50 * (n - 1))
        break;
    }
  }
  for (ll i = 1; i < n; i++) {
    cout << ans[i] << endl;
  }
}