Language: C++

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

int head[55];
int to[105];
int next[105];
int A[105];
int B[105];
int C[55];
int D[55];
int tot=1;
int N, M, S;

int ans[55][20000];

bool vis[55][20000];

int max_coin = 0;

void add(int u, int v, int a, int b)
{
    to[++tot] = v;
    A[tot] = a;
    B[tot] = b;
    next[tot] = head[u];
    head[u] = tot;
}

int main()
{

   cin >> N >> M >>S;

    for(int i = 0; i < M; ++i)
    {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        add(u, v, a, b);
        add(v, u, a, b);
        max_coin += a;
    }

    for(int i = 1; i <= N; ++i)
    {
        cin >> C[i] >> D[i];
        for(int j = 0; j < max_coin; ++j)
            ans[i][j] = 1e9;
    }

    S = min(S, max_coin);


    queue<pair<int, int> > q;
    q.push(make_pair(1, S));

    ans[1][S] = 0;

    while(!q.empty())
    {
        int u = q.front().first;
        int s = q.front().second;
        q.pop();
        vis[u][s] = false;

        for(int i = head[u]; i; i = next[i])
        {
            int v = to[i];

            int diff_min = max(0, A[i]-s);
            int diff_max = max(0, max_coin - s);
            int cnt_min = diff_min / C[u] + diff_min % C[u];
            int cnt_max = diff_max / C[u] + diff_max % C[u];


            for(int j = cnt_min; j <= cnt_max; ++j)
            {
                int ts = s + j * C[u] - A[i];

                if(ans[to[i]][ts] > ans[u][s] + j * D[u] + B[i])
                {
                    ans[to[i]][ts] = ans[u][s] + j * D[u] + B[i];
                    if(!vis[to[i]][ts])
                    {
                        q.push(make_pair(to[i], ts));
                        vis[to[i]][ts] = true;
                    }
                }
            }
        }
    }




   for(int i = 2; i <= N; ++i)
   {
       int res = 1e9;
       for(int j = 0; j < max_coin; ++j)
        res = min(res, ans[i][j]);
       cout << res << endl;

   }

    return 0;
}


Compiler output:
a.cc: In function 'void add(int, int, int, int)':
a.cc:25:5: error: reference to 'next' is ambiguous
   25 |     next[tot] = head[u];
      |     ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:6:5: note:                 'int next [105]'
    6 | int next[105];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:65:37: error: reference to 'next' is ambiguous
   65 |         for(int i = head[u]; i; i = next[i])
      |                                     ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:6:5: note:                 'int next [105]'
    6 | int next[105];
      |     ^~~~