Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int N = 55;
const int Mod = 2019;
#define pi acos(-1)
#define INF 1e18
#define INM INT_MIN
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx, 0, sizeof(axx));
#define metf(axx) memset(axx, -1, sizeof(axx));
#define sd(ax) scanf("%d", &ax)
#define sld(ax) scanf("%lld", &ax)
#define sldd(ax, bx) scanf("%lld %lld", &ax, &bx)
#define sdd(ax, bx) scanf("%d %d", &ax, &bx)
#define sddd(ax, bx, cx) scanf("%d %d %d", &ax, &bx, &cx)
#define sfd(ax) scanf("%lf", &ax)
#define sfdd(ax, bx) scanf("%lf %lf", &ax, &bx)
#define pr(a) printf("%d\n", a)
#define plr(a) printf("%lld\n", a)
/*
最短路的变形,首先要明确一些条件.
对于金币换银币的操作,在一个地方只能用一枚金币换到c[i]枚银币.(也就是说不能用2,3...枚金币,只能进行一次一枚的兑换)
*/
int n, m, s, c[N], dd[N];
struct Node {
  int to, a, b;
};
vector<Node> G[N];
LL dis[N][N * N]; // 边界控制
void slove() {
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= 2500; ++j)
      dis[i][j] = INF;
  typedef tuple<LL, int, int> ple; // dis,u,money,多元组容器
  priority_queue<ple, vector<ple>, greater<ple>> Q;
  dis[1][s] = 0; // 初始化,类似dis[s] = 0.
  Q.push(ple(0, 1, s));
  while (!Q.empty()) {
    int u = get<1>(Q.top());
    LL d = get<0>(Q.top());
    int mon = get<2>(Q.top()); // 身上的银币数
    Q.pop();
    if (d > dis[u][mon])
      continue;
    for (int i = 0; i < G[u].size(); ++i) // 更新相邻点的距离
    {
      int y = G[u][i].to, a = G[u][i].a, b = G[u][i].b;
      if (mon >= a && dis[y][mon - a] > d + b) {
        dis[y][mon - a] = d + b;
        Q.push(ple(dis[y][mon - a], y, mon - a));
      }
    }
    if (dis[u][min(2500, mon + c[u])] > dis[u][mon] + dd[u]) // 兑换
    {
      dis[u][min(2500, mon + c[u])] = dis[u][mon] + dd[u];
      Q.push(ple(dis[u][min(2500, mon + c[u])], u, min(2500, mon + c[u])));
    }
  }
}
int main() {
  sddd(n, m, s);
  while (m--) {
    int x, y, a, b;
    sdd(x, y), sdd(a, b);
    G[x].push_back({y, a, b});
    G[y].push_back({x, a, b});
  }
  for (int i = 1; i <= n; ++i)
    sdd(c[i], dd[i]);
  slove();
  for (int i = 2; i <= n; ++i) {
    LL ans = INF;
    for (int j = 0; j <= 2500; ++j)
      ans = min(ans, dis[i][j]);
    plr(ans);
  }
  // system("pause");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int N = 55;
const int Mod = 2019;
#define pi acos(-1)
#define INF 1e18
#define INM INT_MIN
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx, 0, sizeof(axx));
#define metf(axx) memset(axx, -1, sizeof(axx));
#define sd(ax) scanf("%d", &ax)
#define sld(ax) scanf("%lld", &ax)
#define sldd(ax, bx) scanf("%lld %lld", &ax, &bx)
#define sdd(ax, bx) scanf("%d %d", &ax, &bx)
#define sddd(ax, bx, cx) scanf("%d %d %d", &ax, &bx, &cx)
#define sfd(ax) scanf("%lf", &ax)
#define sfdd(ax, bx) scanf("%lf %lf", &ax, &bx)
#define pr(a) printf("%d\n", a)
#define plr(a) printf("%lld\n", a)
/*
最短路的变形,首先要明确一些条件.
对于金币换银币的操作,在一个地方只能用一枚金币换到c[i]枚银币.(也就是说不能用2,3...枚金币,只能进行一次一枚的兑换)
*/
int n, m, s, c[N], dd[N];
struct Node {
  int to, a, b;
};
vector<Node> G[N];
LL dis[N][N * N]; // 边界控制
void slove() {
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= 2500; ++j)
      dis[i][j] = INF;
  typedef tuple<LL, int, int> ple; // dis,u,money,多元组容器
  priority_queue<ple, vector<ple>, greater<ple>> Q;
  s = min(2500, s); // s很可能会超过2500,需要过滤一下,不然会re
  dis[1][s] = 0;    // 初始化,类似dis[s] = 0.
  Q.push(ple(0, 1, s));
  while (!Q.empty()) {
    int u = get<1>(Q.top());
    LL d = get<0>(Q.top());
    int mon = get<2>(Q.top()); // 身上的银币数
    Q.pop();
    if (d > dis[u][mon])
      continue;
    for (int i = 0; i < G[u].size(); ++i) // 更新相邻点的距离
    {
      int y = G[u][i].to, a = G[u][i].a, b = G[u][i].b;
      if (mon >= a && dis[y][mon - a] > d + b) {
        dis[y][mon - a] = d + b;
        Q.push(ple(dis[y][mon - a], y, mon - a));
      }
    }
    if (dis[u][min(2500, mon + c[u])] > dis[u][mon] + dd[u]) // 兑换
    {
      dis[u][min(2500, mon + c[u])] = dis[u][mon] + dd[u];
      Q.push(ple(dis[u][min(2500, mon + c[u])], u, min(2500, mon + c[u])));
    }
  }
}
int main() {
  sddd(n, m, s);
  while (m--) {
    int x, y, a, b;
    sdd(x, y), sdd(a, b);
    G[x].push_back({y, a, b});
    G[y].push_back({x, a, b});
  }
  for (int i = 1; i <= n; ++i)
    sdd(c[i], dd[i]);
  slove();
  for (int i = 2; i <= n; ++i) {
    LL ans = INF;
    for (int j = 0; j <= 2500; ++j)
      ans = min(ans, dis[i][j]);
    plr(ans);
  }
  // system("pause");
  return 0;
}