Problem p02703 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define mod 1000000007
#define maxn 2500ll
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define endl "\n"
struct Cell {
  ll v, cst, mt;
};
vector<Cell> adj[55];
ll dp[55][2505];
pii a[55];
ll dijkstra(ll u, ll c) {
  set<pair<ll, pii>> st;
  pii temp;
  temp.fi = u;
  temp.se = c;
  st.insert({0, temp});
  dp[u][c] = 0;
  while (!st.empty()) {
    pair<ll, pii> temp = *st.begin();
    st.erase(st.begin());
    ll mnt = temp.fi;
    u = (temp.se).fi;
    c = (temp.se).se;
    if (c < maxn) {
      ll val = min(maxn, c + a[u].fi);
      ll &res = dp[u][val];
      if (res > mnt + a[u].se) {
        st.erase({res, {u, val}});
        res = mnt + a[u].se;
        st.insert({res, {u, val}});
      }
    }
    for (auto it = adj[u].begin(); it != adj[u].end(); it++) {
      Cell temp = *it;
      if (c >= temp.cst) {
        ll &res = dp[temp.v][c - temp.cst];
        if (res > mnt + temp.mt) {
          st.erase({res, {temp.v, c - temp.cst}});
          res = mnt + temp.mt;
          st.insert({res, {temp.v, c - temp.cst}});
        }
      }
    }
  }
}
int main() {
  ios;
  ll i, m, s, n, u, j, k;
  cin >> n >> m >> s;
  s = min(s, maxn);
  for (i = 1; i <= m; i++) {
    Cell temp;
    cin >> u >> temp.v >> temp.cst >> temp.mt;
    adj[u].push_back(temp);
    swap(temp.v, u);
    adj[u].push_back(temp);
  }
  for (i = 1; i <= n; i++)
    cin >> a[i].fi >> a[i].se;
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= maxn; j++)
      dp[i][j] = LLONG_MAX;
  }
  dijkstra(1, s);
  for (i = 2; i <= n; i++) {
    ll min1 = LLONG_MAX;
    for (j = 0; j <= maxn; j++)
      min1 = min(min1, dp[i][j]);
    cout << min1 << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define mod 1000000007
#define maxn 2500ll
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define endl "\n"
struct Cell {
  ll v, cst, mt;
};
vector<Cell> adj[55];
ll dp[55][2505];
pii a[55];
void dijkstra(ll u, ll c) {
  set<pair<ll, pii>> st;
  pii temp;
  temp.fi = u;
  temp.se = c;
  st.insert({0, temp});
  dp[u][c] = 0;
  while (!st.empty()) {
    pair<ll, pii> temp = *st.begin();
    st.erase(st.begin());
    ll mnt = temp.fi;
    u = (temp.se).fi;
    c = (temp.se).se;
    if (c < maxn) {
      ll val = min(maxn, c + a[u].fi);
      ll &res = dp[u][val];
      if (res > mnt + a[u].se) {
        st.erase({res, {u, val}});
        res = mnt + a[u].se;
        st.insert({res, {u, val}});
      }
    }
    for (auto it = adj[u].begin(); it != adj[u].end(); it++) {
      Cell temp = *it;
      if (c >= temp.cst) {
        ll &res = dp[temp.v][c - temp.cst];
        if (res > mnt + temp.mt) {
          st.erase({res, {temp.v, c - temp.cst}});
          res = mnt + temp.mt;
          st.insert({res, {temp.v, c - temp.cst}});
        }
      }
    }
  }
}
int main() {
  ios;
  ll i, m, s, n, u, j, k;
  cin >> n >> m >> s;
  s = min(s, maxn);
  for (i = 1; i <= m; i++) {
    Cell temp;
    cin >> u >> temp.v >> temp.cst >> temp.mt;
    adj[u].push_back(temp);
    swap(temp.v, u);
    adj[u].push_back(temp);
  }
  for (i = 1; i <= n; i++)
    cin >> a[i].fi >> a[i].se;
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= maxn; j++)
      dp[i][j] = LLONG_MAX;
  }
  dijkstra(1, s);
  for (i = 2; i <= n; i++) {
    ll min1 = LLONG_MAX;
    for (j = 0; j <= maxn; j++)
      min1 = min(min1, dp[i][j]);
    cout << min1 << endl;
  }
}