Language: C++

// abc164_e
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((ll)1e12)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


struct Graph {

    struct Edge {
        int u, v;
        ll money;
        ll cost;
        Edge() {}
        Edge(int u, int v, ll w, ll t) : u(u), v(v), money(w), cost(t) {}
        friend ostream& operator<<(ostream& os, const Edge& e) {
            cout << "(" << e.u << "->" << e.v << "," << e.money << "," << e.cost << ")"; return os;
        }
    };

    int n;

    vector<vector<Edge>> edges;
    Graph(int n): n(n), edges(n) {}

    void add_edge(int u, int v, ll w, ll t){
        edges[u].emplace_back(u, v, w, t);
        edges[v].emplace_back(v, u, w, t);
    }

    vector<ll> dijkstra(int s, int S, vector<P>& trades){

        // コスト（時間）, (node, 銀貨)
        using PP = pair<ll, pair<int, ll>>;

        priority_queue<PP, vector<PP>, greater<PP>> pq;
        pq.push(PP(0, P(s, S)));

        vector<ll> dist(n, INF);
        dist[s] = 0;

        // node, 銀貨に対する最短時間
        map<P, ll> best_costs;
        best_costs[P(s, S)] = 0;

        // 全部たどり着くまでこれは使わない。
        ll now_max_cost = INF;

        while (!pq.empty()){
            PP pp = pq.top(); pq.pop();

            ll cost = pp.first;
            int u = pp.second.first;
            ll money = pp.second.second;

            print(u, cost, money, now_max_cost, dist);

            // 全部たどり着いていて、かつ現時点で一番時間がかかる地点までの時間よりも超えるなら終わり
            if (now_max_cost != INF && cost > now_max_cost) {
                return dist;
            }

            // 移動
            for (auto edge: edges[u]){

                if (money < edge.money) continue;

                ll nmoney = money - edge.money;
                ll ncost = cost + edge.cost;

                // 状態更新
                if (ncost < dist[edge.v]){
                    dist[edge.v] = ncost;

                    // 全部たどりつけたかチェック & 最低この時間でたどり着けるという時間をセットする
                    now_max_cost = 0;
                    REP(i, n) {
                        now_max_cost = max(dist[i], now_max_cost);
                    }
                }

                // 移動
                P node = P(edge.v, nmoney);
                if (best_costs.find(node) == best_costs.end() || ncost < best_costs[node]) {
                    best_costs[node] = ncost;
                    pq.push(PP(ncost, node));
                }
            }

            // 換金
            ll nmoney = money + trades[u].first;
            ll ncost = cost + trades[u].second;

            // 絶対使わない状態ならいらない。
            // 最大でも50都市 x 50枚しか金貨は使わない
            // 全部たどり着いていて、かつ現時点で一番時間がかかる地点までの時間よりも超えるならいらない
            if (money > 2500 || (now_max_cost != INF && ncost > now_max_cost)) {
                continue;
            }
            pq.push(PP(ncost, P(u, nmoney)));

        }

        return dist;
    }
};

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M, S;
    cin >> N >> M >> S;

    Graph g(N);
    REP(i, M){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        g.add_edge(u, v, a, b);
    }

    vector<P> trades(N);
    REP(i, N){
        cin >> trades[i].first >> trades[i].second;
    }

    vector<ll> ans = g.dijkstra(0, S, trades);

    REPN(i, 1, N){
        print(ans[i]);
    }




    return 0;
}


Compiler output:
a.cc: In instantiation of 'void print(const T&) [with T = std::vector<long long int>]':
a.cc:24:105:   recursively required from 'void print(const T&, const A& ...) [with T = long long int; A = {long long int, long long int, std::vector<long long int, std::allocator<long long int> >}]'
   24 | template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
      |                                                                                                    ~~~~~^~~~~~~~~
a.cc:24:105:   required from 'void print(const T&, const A& ...) [with T = int; A = {long long int, long long int, long long int, std::vector<long long int, std::allocator<long long int> >}]'
a.cc:76:18:   required from here
   76 |             print(u, cost, money, now_max_cost, dist);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:23:47: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and 'const std::vector<long long int>')
   23 | template<class T> void print(const T& x){cout << x << endl;}
      |                                          ~~~~~^~~~
In file included from /usr/include/c++/14/istream:41,
                 from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127,
                 from a.cc:2:
/usr/include/c++/14/ostream:116:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  116 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:116:36: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'}
  116 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:125:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]'
  125 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:125:32: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}
  125 |       operator<<(__ios_type& (*__pf)(__ios_type&))
      |                  ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:135:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  135 |       operator<<(ios_base& (*__pf) (ios_base&))
      |       ^~~~~~~~
/usr/include/c++/14/ostream:135:30: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'std::ios_base& (*)(std::ios_base&)'
  135 |       operator<<(ios_base& (*__pf) (ios_base&))
      |                  ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  174 |       operator<<(long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:174:23: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'long int'
  174 |       operator<<(long __n)
      |                  ~~~~~^~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  178 |       operator<<(unsigned long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:178:32: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'long unsigned int'
  178 |       operator<<(unsigned long __n)
      |                  ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  182 |       operator<<(bool __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:182:23: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'bool'
  182 |       operator<<(bool __n)
      |                  ~~~~~^~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
   96 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:97:22: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'short int'
   97 |     operator<<(short __n)
      |                ~~~~~~^~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  189 |       operator<<(unsigned short __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:189:33: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'short unsigned int'
  189 |       operator<<(unsigned short __n)
      |                  ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
  110 |     basic_ostream<_CharT, _Traits>::
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:111:20: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'int'
  111 |     operator<<(int __n)
      |                ~~~~^~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  200 |       operator<<(unsigned int __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:200:31: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'unsigned int'
  200 |       operator<<(unsigned int __n)
      |                  ~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  211 |       operator<<(long long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:211:28: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'long long int'
  211 |       operator<<(long long __n)
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  215 |       operator<<(unsigned long long __n)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:215:37: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'long long unsigned int'
  215 |       operator<<(unsigned long long __n)
      |                  ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  231 |       operator<<(double __f)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:231:25: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'double'
  231 |       operator<<(double __f)
      |                  ~~~~~~~^~~
/usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  235 |       operator<<(float __f)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:235:24: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'float'
  235 |       operator<<(float __f)
      |                  ~~~~~~^~~
/usr/include/c++/14/ostream:243:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
  243 |       operator<<(long double __f)
      |       ^~~~~~~~
/usr/include/c++/14/ostream:243:30: note:   no known conversion for argument 1 from 'const std::vector<long long int>' to 'long double'
  243 |       operator<<(long double __f)
      |                  ~~~~~~~~~~~~^~~
/usr/includ