Language: C

#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

struct Edge {
    int to;
    int64_t cost, time;
    int p;

    inline Edge() noexcept {}
    inline Edge(int a, int64_t c, int64_t t, int p = 0) noexcept
        : to(a), cost(c), time(t), p(p) {}

    inline bool operator<(const Edge &rhs) const noexcept {
        return cost < rhs.time;
    }
    inline bool operator>(const Edge &rhs) const noexcept {
        return cost > rhs.time;
    }
};

i64 N, M, S;
vector<vector<Edge>> G;
vector<i64> C, D;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    read(N, M, S);
    G.resize(N);

    rep(i, 0, M) {
        var(i64, u, v, cost, time);
        --u, --v;
        G[u].emplace_back(v, cost, time);
        G[v].emplace_back(u, cost, time);
    }

    C.resize(N);
    D.resize(N);
    rep(i, 0, N) { read(C[i], D[i]); }

    auto dist = makeV(LINF, N, N + 5);
    const int UNDEFIED = N + 1;
    dist[0][UNDEFIED] = 0;
    priority_queue<Edge, vector<Edge>, greater<Edge>> pq;
    pq.emplace(0, S, 0, UNDEFIED);

    while (!pq.empty()) {
        const auto cur = pq.top();
        pq.pop();
        const int curNode = cur.to;
        const i64 curMoney = cur.cost;
        const i64 curElapsed = cur.time;
        const int p = cur.p;

        for (const auto e : G[curNode]) {
            if (p == UNDEFIED) {
                const i64 husoku = max<i64>(0, e.cost - curMoney);
                if (husoku <= 0) {
                    const int nxtNode = e.to;
                    const i64 nxtMoney = curMoney - e.cost;
                    const i64 nxtElapsed = curElapsed + e.time;
                    if (chmin(dist[nxtNode][p], nxtElapsed)) {
                        pq.emplace(nxtNode, nxtMoney, nxtElapsed, p);
                    }
                }

                {
                    const int newP = curNode;
                    const i64 swapNum = (husoku + C[newP] - 1) / C[newP];
                    const i64 swapTime = swapNum * D[newP];

                    const int nxtNode = e.to;
                    const i64 nxtMoney = curMoney + swapNum * C[newP] - e.cost;
                    const i64 nxtElapsed = curElapsed + swapTime + e.time;

                    if (chmin(dist[nxtNode][newP], nxtElapsed)) {
                        pq.emplace(nxtNode, nxtMoney, nxtElapsed, newP);
                    }
                }

            } else {
                const i64 husoku = max<i64>(0, e.cost - curMoney);
                const i64 swapNum = (husoku + C[p] - 1) / C[p];
                const i64 swapTime = swapNum * D[p];

                const int nxtNode = e.to;
                const i64 nxtMoney = curMoney + swapNum * C[p] - e.cost;
                const i64 nxtElapsed = curElapsed + swapTime + e.time;

                if (chmin(dist[nxtNode][p], nxtElapsed)) {
                    pq.emplace(nxtNode, nxtMoney, nxtElapsed, p);
                }
            }
        }
    }

    rep(u, 1, N) { print(*min_element(all(dist[u]))); }

    return 0;
}


Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include "bits/stdc++.h"
      |          ^~~~~~~~~~~~~~~
compilation terminated.