Language: C++

//header
#ifdef LOCAL
    #include "cxx-prettyprint-master/prettyprint.hpp"
    #define debug(x) cout << x << endl
#else
    #define debug(...) 42
#endif
    #pragma GCC optimize("Ofast")
    #include <bits/stdc++.h>
    //types
    using namespace std;
    using ll = long long;
    using ld = long double;
    typedef pair < ll , ll > Pl;
    typedef pair < int, int > Pi;
    typedef vector<ll> vl;
    typedef vector<int> vi;
    template< typename T >
    using mat = vector< vector< T > >;
    template< int mod >
    struct modint {
        int x;

        modint() : x(0) {}

        modint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

        modint &operator+=(const modint &p) {
            if((x += p.x) >= mod) x -= mod;
            return *this;
        }

        modint &operator-=(const modint &p) {
            if((x += mod - p.x) >= mod) x -= mod;
            return *this;
        }

        modint &operator*=(const modint &p) {
            x = (int) (1LL * x * p.x % mod);
            return *this;
        }

        modint &operator/=(const modint &p) {
            *this *= p.inverse();
            return *this;
        }

        modint operator-() const { return modint(-x); }

        modint operator+(const modint &p) const { return modint(*this) += p; }

        modint operator-(const modint &p) const { return modint(*this) -= p; }

        modint operator*(const modint &p) const { return modint(*this) *= p; }

        modint operator/(const modint &p) const { return modint(*this) /= p; }

        bool operator==(const modint &p) const { return x == p.x; }

        bool operator!=(const modint &p) const { return x != p.x; }

        modint inverse() const {
            int a = x, b = mod, u = 1, v = 0, t;
            while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
            }
            return modint(u);
        }

        modint pow(int64_t n) const {
            modint ret(1), mul(x);
            while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
            }
            return ret;
        }

        friend ostream &operator<<(ostream &os, const modint &p) {
            return os << p.x;
        }

        friend istream &operator>>(istream &is, modint &a) {
            int64_t t;
            is >> t;
            a = modint< mod >(t);
            return (is);
        }

        static int get_mod() { return mod; }
    };
    //abreviations
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()
    #define rep_(i, a_, b_, a, b, ...) for (int i = (a), max_i = (b); i < max_i; i++)
    #define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
    #define rev(i,n) for(int i=n-1;i>=0;i--)
    #define SZ(x) ((int)(x).size())
    #define pb(x) push_back(x)
    #define eb(x) emplace_back(x)
    #define ff first
    #define ss second
    #define mp make_pair
    #define print(x) cout << x << endl
    #define lsum(x) accumulate(x, 0LL)
    //functions
    ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
    ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
    template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
    template< typename T >
    T mypow(T x, ll n) {
        T ret = 1;
        while(n > 0) {
            if(n & 1) (ret *= x);
            (x *= x);
            n >>= 1;
        }
        return ret;
    }
    ll modpow(ll x, ll n, const ll mod) {
        ll ret = 1;
        while(n > 0) {
            if(n & 1) (ret *= x);
            (x *= x);
            n >>= 1;
            x%=mod;
            ret%=mod;
        }
        return ret;
    }
    uint64_t my_rand(void) {
        static uint64_t x = 88172645463325252ULL;
        x = x ^ (x << 13); x = x ^ (x >> 7);
        return x = x ^ (x << 17);
    }
    //graph template
    template< typename T >
    struct edge {
        int src, to;
        T cost;

        edge(int to, T cost) : src(-1), to(to), cost(cost) {}

        edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

        edge &operator=(const int &x) {
            to = x;
            return *this;
        }
        operator int() const { return to; }
    };

    template< typename T >
    using Edges = vector< edge< T > >;
    template< typename T >
    using WeightedGraph = vector< Edges< T > >;
    using UnWeightedGraph = vector< vector< int > >;

//constant
#define INF 1000000000000000005LL
#define inf 1000000005
#define mod 1000000007LL
#define endl '\n'
typedef modint<mod> mint;
#define int ll
const long double eps = 0.001;
const long double PI  = 3.141592653589793;
//library
struct HLD {
    vector<vector<int>> G;
    vector<int> parent, depth, sub_size, v_id, id_to_v, head;
    HLD(int n):
        G(n), v_id(n, -1), head(n), sub_size(n, 1), parent(n, -1), depth(n, 0), id_to_v(n){}

    void add_edge(int u, int v){
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    void build(int root=0){
        int pos = 0;
        dfs_size(root);
        head[root] = root;
        dfs_hld(root, pos); 
    }

    void dfs_size(int v){
        for(int &nv:G[v]){
            if(nv==parent[v]){
                nv = G[v].back();
                G[v].pop_back();
            }
        }
        for(int &nv:G[v]){
            parent[nv] = v;
            depth[nv] = depth[v]+1;
            dfs_size(nv);
            sub_size[v]+=sub_size[nv];
            if(sub_size[nv]>sub_size[G[v][0]]) swap(nv, G[v][0]);
        }
    }

    void dfs_hld(int v, int &pos){
        v_id[v]=pos;
        id_to_v[pos++]=v;
        for(int nv:G[v]){
            head[nv]=(nv==G[v][0]?head[v]:nv);
            dfs_hld(nv, pos);
        }
    }

    int lca(int u, int v){
        while(1){
            if(v_id[u]>v_id[v]) swap(u, v);
            if(head[u] == head[v]) return u;
            v = parent[head[v]];
        }
    }

    int distance(int u, int v){
        return depth[u]+depth[v]-2*depth[lca(u, v)];
    }

    template<typename F>
    void update(int u, int v, const F& f){
        while(1){
            if(v_id[u]>v_id[v]) swap(u, v);
            f(max(v_id[head[v]], v_id[u]), v_id[v]+1);
            if(head[u]!=head[v]) v = parent[head[v]];
            else break;
        }
    }

    template<typename T,typename Q,typename F>
    T query(int u, int v, T id, const Q& q, const F& f){
        T l = id, r = id;
        while(1){
            if(v_id[u]>v_id[v]){
                swap(u, v);
                swap(l, r);
            }
            l = f(l, q(max(v_id[head[v]], v_id[u]), v_id[v]+1));
            if(head[u]!=head[v]) v=parent[head[v]];
            else break;
        }
        return f(l, r);
    }

    template<typename F>
    void update_edge(int u, int v, const F& f){
        while(1){
            if(v_id[u]>v_id[v]) swap(u, v);
            if(head[u]!=head[v]){
                f(v_id[head[v]], v_id[v]+1);
                v = parent[head[v]];
            }else{
                if(u!=v) f(v_id[u]+1, v_id[v]+1);
                break;
            }
        }
    }

    template<typename T,typename Q,typename F>
    T query_edge(int u, int v, T id, const Q& q, const F& f){
        T l = id, r = id;
        while(1){
            if(v_id[u]>v_id[v]){
                swap(u, v);
                swap(l, r);
            }
            if(head[u]!=head[v]){
                l = f(l, q(v_id[head[v]], v_id[v]+1));
                v = parent[head[v]];
            }else{
                if(u!=v) l = f(l, q(v_id[u]+1, v_id[v]+1));
                break;
            }
        }
        return f(l, r);
    }
};
template< typename Monoid >
struct SegmentTree {
    using F = function< Monoid(Monoid, Monoid) >;

    int sz;
    vector< Monoid > seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while(sz < n) sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x) {
        seg[k + sz] = x;
    }

    void build() {
        for(int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid &x) {
        k += sz;
        seg[k] = x;
        while(k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) L = f(L, seg[a++]);
            if(b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const {
        return seg[k + sz];
    }

    template< typename C >
    int find_subtree(int a, const C &check, Monoid &M, bool type) {
        while(a < sz) {
            Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
            if(check(nxt)) a = 2 * a + type;
            else M = nxt, a = 2 * a + 1 - type;
        }
        return a - sz;
    }


    template< typename C >
    int find_first(int a, const C &check) {
        Monoid L = M1;
        if(a <= 0) {
            if(check(f(L, seg[1]))) return find_subtree(1, check, L, false);
            return -1;
        }
        int b = sz;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) {
                Monoid nxt = f(L, seg[a]);
                if(check(nxt)) return find_subtree(a, check, L, false);
                L = nxt;
                ++a;
            }
        }
        return -1;
    }

    template< typename C >
    int find_last(int b, const C &check) {
        Monoid R = M1;
        if(b >= sz) {
            if(check(f(seg[1], R))) return find_subtree(1, check, R, true);
            return -1;
        }
        int a = sz;
        for(b += sz; a < b; a >>= 1, b >>= 1) {
            if(b & 1) {
                Monoid nxt = f(seg[--b], R);
                if(check(nxt)) return find_subtree(b, check, R, true);
                R = nxt;
            }
        }
        return -1;
    }
};
struct e{
    int a, b, c, d;
    e(int p, int q, int r, int s){
        a = p;b = q;c = r;d = s;
    }
};

struct color{
    mat<int> cnt, dist, index, cumsum, cumdist;
    color(int n):
        cnt(n), dist(n), index(n), cumsum(n), cumdist(n){}
    
    void update(int v, int c, int d){
        cnt[c].pb(1);
        dist[c].pb(d);
        index[c].pb(v);
    }
    void build(){
        int n = SZ(cnt);
        rep(i, n){
            int l = SZ(cnt[i]);
            sort(all(cnt[i]));
            sort(all(index[i]));
            sort(all(dist[i]));
            cumdist[i].resize(l+1);
            cumsum[i].resize(l+1);
            rep(j, l){
                cumsum[i][j+1] = cumsum[i][j]+cnt[i][j];
                cumdist[i][j+1] = cumdist[i][j]+dist[i][j];
            }
        }
    }
    int query1(int u, int v, int c){
        int x = lower_bound(all(index[c]), u)-index[c].begin();
        int y = lower_bound(all(index[c]), v)-index[c].begin();
        return cumsum[c][y]-cumsum[c][x];
    } 

    int query2(int u, int v, int c){
        int x = lower_bound(all(index[c]), u)-index[c].begin();
        int y = lower_bound(all(index[c]), v)-index[c].begin();
        return cumdist[c][y]-cumdist[c][x];
    } 
};
//main
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(20);
    int n, q; cin>>n>>q;
    HLD hld(n);
    SegmentTree<ll> seg(n, [](int a, int b){return a+b;}, 0);
    color cum(n);
    vector<e> edges;
    rep(i, n-1){
        int a, b, c, d;
        cin>>a>>b>>c>>d;
        hld.add_edge(a-1, b-1);
        edges.pb(e(a-1, b-1, c, d));
    }
    hld.build();
    for(auto &ee:edges){
        if(hld.depth[ee.a]<hld.depth[ee.b]) swap(ee.a, ee.b);
        seg.update(hld.v_id[ee.a], ee.d);
        cum.update(hld.v_id[ee.a], ee.c, ee.d);
    }
    cum.build();
    rep(i, q){
        int x, y, u, v;
        cin>>x>>y>>u>>v;
        u--; v--;
        int dist = hld.query_edge(u, v, 0, [&](int a, int b){return seg.query(a, b);}, 
                                    [](int a, int b){return a+b;});
        int cnt = hld.query_edge(u, v, 0, [&](int a, int b){return cum.query1(a, b, x);}, 
                                    [](int a, int b){return (a+b);});  
        int c_dist = hld.query_edge(u, v, 0, [&](int a, int b){return cum.query2(a, b, x);}, 
                                    [](int a, int b){return (a+b);});
        cout << dist-c_dist+cnt*y << endl;
    }
}   


Compiler output:
a.cc:169:13: error: '::main' must return 'int'
  169 | #define int ll
      |             ^~
a.cc:426:1: note: in expansion of macro 'int'
  426 | int main(){
      | ^~~