Problem p02703 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, pair<int, int>> P;
struct edge {
  int to;
  int cost;
  long long time;
};
int N, M, S;
int C[55];
long long D[55];
vector<edge> E[55];
long long ans[55];
long long dp[55]
            [2510]; // dp[頂点i][銀貨をちょうどj枚持っている（50N枚以上は10N）]
long long INF = 1145141919810364364;
priority_queue<P, vector<P>, greater<P>> que;
int main() {
  cin >> N >> M >> S;
  for (int i = 0; i < M; i++) {
    int u, v, a;
    long long b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    E[u].push_back((edge){v, a, b});
    E[v].push_back((edge){u, a, b});
  }
  for (int i = 0; i < N; i++)
    cin >> C[i] >> D[i];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= N * 50; j++) {
      dp[i][j] = INF;
    }
  }
  que.push(make_pair(0, make_pair(0, min(S, 50 * N))));
  dp[0][min(S, 50 * N)] = 0;
  while (que.size()) {
    P p = que.top();
    que.pop();
    long long t = p.first;
    int v = p.second.first;
    int m = p.second.second;
    if (t > dp[v][m])
      continue;
    if (m == 50 * N) {
      for (auto e : E[v]) {
        if (t + e.time >= dp[e.to][50 * N])
          continue;
        dp[e.to][50 * N] = t + e.time;
        que.push(make_pair(t + e.time, make_pair(e.to, 50 * N)));
      }
    } else {
      for (auto e : E[v]) {
        if (m < e.cost)
          continue;
        if (t + e.time >= dp[e.to][m - e.cost])
          continue;
        dp[e.to][m - e.cost] = t + e.time;
        que.push(make_pair(t + e.time, make_pair(e.to, m - e.cost)));
      }
      if (dp[v][min(m + C[v], 50 * N)] <= t + D[v])
        continue;
      dp[v][min(m + C[v], 50 * N)] = t + D[v];
      que.push(make_pair(t + D[v], make_pair(v, min(m + C[v], 50 * N))));
    }
  }
  fill(ans, ans + N, INF);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 50 * N; j++) {
      ans[i] = min(ans[i], dp[i][j]);
    }
  }
  for (int i = 1; i < N; i++)
    cout << ans[i] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, pair<int, int>> P;
struct edge {
  int to;
  int cost;
  long long time;
};
int N, M, S;
int C[55];
long long D[55];
vector<edge> E[55];
long long ans[55];
long long dp[55]
            [2510]; // dp[頂点i][銀貨をちょうどj枚持っている（50N枚以上は50N）]
long long INF = 1145141919810364364;
priority_queue<P, vector<P>, greater<P>> que;
int main() {
  cin >> N >> M >> S;
  for (int i = 0; i < M; i++) {
    int u, v, a;
    long long b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    E[u].push_back((edge){v, a, b});
    E[v].push_back((edge){u, a, b});
  }
  for (int i = 0; i < N; i++)
    cin >> C[i] >> D[i];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= N * 50; j++) {
      dp[i][j] = INF;
    }
  }
  que.push(make_pair(0, make_pair(0, min(S, 50 * N))));
  dp[0][min(S, 50 * N)] = 0;
  while (que.size()) {
    P p = que.top();
    que.pop();
    long long t = p.first;
    int v = p.second.first;
    int m = p.second.second;
    if (t > dp[v][m])
      continue;
    if (m == 50 * N) {
      for (auto e : E[v]) {
        if (t + e.time > dp[e.to][50 * N])
          continue;
        dp[e.to][50 * N] = t + e.time;
        que.push(make_pair(t + e.time, make_pair(e.to, 50 * N)));
      }
    } else {
      for (auto e : E[v]) {
        if (m < e.cost)
          continue;
        if (t + e.time > dp[e.to][m - e.cost])
          continue;
        dp[e.to][m - e.cost] = t + e.time;
        que.push(make_pair(t + e.time, make_pair(e.to, m - e.cost)));
      }
      if (dp[v][min(m + C[v], 50 * N)] < t + D[v])
        continue;
      dp[v][min(m + C[v], 50 * N)] = t + D[v];
      que.push(make_pair(t + D[v], make_pair(v, min(m + C[v], 50 * N))));
    }
  }
  fill(ans, ans + N, INF);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 50 * N; j++) {
      ans[i] = min(ans[i], dp[i][j]);
    }
  }
  for (int i = 1; i < N; i++)
    cout << ans[i] << endl;
}