Language: C++

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

const int LIM = 2500;
const long long INF = (long long) 1e18;

int C[55], D[55];
int visit[55][2505];
long long SP[55][2505];

vector< vector<int> > X[55];
priority_queue< vector<int>, vector< vector<int> >, greater< vector<int> > > Q;

void relax(int ux, int uy, int vx, int vy, int w)
{
    if(SP[vx][vy] > SP[ux][uy] + w)
    {
        SP[vx][vy] = SP[ux][uy] + w;
        Q.push({SP[vx][vy], vx, vy});
    }
}

int main() {
    int n, m, s;
    cin >> n >> m >> s;

    while(m--)
    {
        int u, v, a, b;
        cin >> u >> v >> a >> b;

        X[u].push_back({v, a, b});
        X[v].push_back({u, a, b});
    }

    for (int i=1; i<=n; i++)
        cin >> C[i] >> D[i];

    for (int i=1; i<=n; i++)
        for (int j=0; j<=LIM; j++)
            SP[i][j] = INF;
    
    s = min(s, LIM);
    SP[1][s] = 0;
    Q.push({SP[1][s], 1, s});

    while(!Q.empty()) {
        auto q = Q.top();
        Q.pop();

        int indx = q[1], coins = q[2];

        if(visit[indx][coins])
            continue;
        
        visit[indx][coins] = 1;

        for (int i=1; coins+i<=LIM && i<=C[indx]; i++)
            if (!visit[indx][coins+i])
                relax(indx, coins, indx, coins + i, D[indx]);
        
        for (auto x : X[indx])
            if (x[1] <= coins && !visit[ x[0] ][ coins - x[1] ])
                relax(indx, coins, x[0], coins - x[1], x[2]);
    }

    for (int i=2; i<=n; i++)
        cout << *min_element(SP[i], SP[i]+LIM+1) << "\n";

    return 0;
}


Compiler output:
a.cc: In function 'void relax(int, int, int, int, int)':
a.cc:19:26: warning: narrowing conversion of 'SP[vx][vy]' from 'long long int' to 'int' [-Wnarrowing]
   19 |         Q.push({SP[vx][vy], vx, vy});
      |                 ~~~~~~~~~^
a.cc:19:26: warning: narrowing conversion of 'SP[vx][vy]' from 'long long int' to 'int' [-Wnarrowing]
a.cc: In function 'int main()':
a.cc:45:20: warning: narrowing conversion of 'SP[1][s]' from 'long long int' to 'int' [-Wnarrowing]
   45 |     Q.push({SP[1][s], 1, s});
      |             ~~~~~~~^
a.cc:45:20: warning: narrowing conversion of 'SP[1][s]' from 'long long int' to 'int' [-Wnarrowing]
a.cc:53:12: error: reference to 'visit' is ambiguous
   53 |         if(visit[indx][coins])
      |            ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:8:5: note:                 'int visit [55][2505]'
    8 | int visit[55][2505];
      |     ^~~~~
a.cc:56:9: error: reference to 'visit' is ambiguous
   56 |         visit[indx][coins] = 1;
      |         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:8:5: note:                 'int visit [55][2505]'
    8 | int visit[55][2505];
      |     ^~~~~
a.cc:59:18: error: reference to 'visit' is ambiguous
   59 |             if (!visit[indx][coins+i])
      |                  ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:8:5: note:                 'int visit [55][2505]'
    8 | int visit[55][2505];
      |     ^~~~~
a.cc:63:35: error: reference to 'visit' is ambiguous
   63 |             if (x[1] <= coins && !visit[ x[0] ][ coins - x[1] ])
      |                                   ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:8:5: note:                 'int visit [55][2505]'
    8 | int visit[55][2505];
      |     ^~~~~