Language: C++

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

using namespace std;
using pii=pair<int,int>;
using ll=long long;

struct EDGE{
    int dst;
    int color;
    int len;
};

void dfs(int now, vector<bool>& visited, vector<vector<pair<pii,map<int,pii>>>>& parent, vector<vector<EDGE>>& adj, vector<int>& lv)
{
    for(auto& e : adj[now]){
        if(!visited[e.dst]){
            lv[e.dst]=lv[now]+1;
            parent[e.dst][0].first.first=now;
            parent[e.dst][0].first.second+=e.len;
            auto ret=parent[e.dst][0].second.insert({e.color,{1,e.len}});
            if(!ret.second){
                ret.first->second.first+=1;
                ret.first->second.second+=e.len;
            }
            visited[e.dst]=true;
            dfs(e.dst,visited,parent,adj,lv);
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n,q;
    cin>>n>>q;
    vector<vector<EDGE>> adj(n);
    vector<bool> visited(n);
    vector<int> lv(n);
    vector<vector<pair<pii,map<int,pii>>>> parent(n,vector<pair<pii,map<int,pii>>>(17));
    for(int i=0; i<n-1; i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        adj[a-1].push_back({b-1,c,d});
        adj[b-1].push_back({a-1,c,d});
    }
    
    visited[0]=true;
    dfs(0,visited,parent,adj,lv);
    
    for(int i=1; i<17; i++){
        for(int j=0; j<n; j++){
            int p=parent[j][i-1].first.first;
            parent[j][i].first.first=parent[p][i-1].first.first;
            parent[j][i].first.second=parent[j][i-1].first.second+parent[p][i-1].first.second;
            for(auto& c : parent[j][i-1].second){
                auto ret=parent[j][i].second.insert(c);
                if(!ret.second){
                    ret.first->second.first+=c.second.first;
                    ret.first->second.second+=c.second.second;
                }
            }
            for(auto& c : parent[p][i-1].second){
                auto ret=parent[j][i].second.insert(c);
                if(!ret.second){
                    ret.first->second.first+=c.second.first;
                    ret.first->second.second+=c.second.second;
                }
            }
        }
    }
    
    for(int i=0; i<q; i++){
        int x,y,u,v;
        cin>>x>>y>>u>>v;
        u-=1;
        v-=1;
        int len=0;
        int colorlen=0;
        int color=0;
        for(int j=16; j>=0; j--){
            if(lv[u]==lv[v]) break;
            if(lv[u]-(1<<j))>=lv[v]){
                len+=parent[u][j].first.second;
                auto ret=parent[u][j].second.find(x);
                if(ret!=parent[u][j].second.end()){
                    color+=ret->second.first;
                    colorlen+=ret->second.second;
                }
                u=parent[u][j].first.first;
            }
            if(lv[v]-(1<<j)>=lv[u]){
                len+=parent[v][j].first.second;
                auto ret=parent[v][j].second.find(x);
                if(ret!=parent[v][j].second.end()){
                    color+=ret->second.first;
                    colorlen+=ret->second.second;
                }
                v=parent[v][j].first.first;
            }
        }
        
        if(u!=v){
            for(int j=16; j>=0; j--){
                if(parent[u][j].first.first!=parent[v][j].first.first){
                    len+=parent[u][j].first.second;
                    len+=parent[v][j].first.second;
                    auto ret1=parent[u][j].second.find(x);
                    if(ret1!=parent[u][j].second.end()){
                        color+=ret1->second.first;
                        colorlen+=ret1->second.second;
                    }
                    auto ret2=parent[v][j].second.find(x);
                    if(ret2!=parent[v][j].second.end()){
                        color+=ret2->second.first;
                        colorlen+=ret2->second.second;
                    }
                    u=parent[u][j].first.first;
                    v=parent[v][j].first.first;
                }
            }
            len+=parent[u][0].first.second;
            len+=parent[v][0].first.second;
            auto ret1=parent[u][0].second.find(x);
            if(ret1!=parent[u][0].second.end()){
                color+=ret1->second.first;
                colorlen+=ret1->second.second;
            }
            auto ret2=parent[v][0].second.find(x);
            if(ret2!=parent[v][0].second.end()){
                color+=ret2->second.first;
                colorlen+=ret2->second.second;
            }
        }
        
        cout<<len-colorlen+(y*color)<<"\n";
    }
    
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:94:29: error: expected primary-expression before '>=' token
   94 |             if(lv[u]-(1<<j))>=lv[v]){
      |                             ^~