Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
typedef long long int ll;
typedef long double ld;
using namespace std;
#define vvv vector<vector<vector<long long int>>>
#define vvvl(a, b, c, d) vector<vector<vector<long long int>>>(a, vector<vector<long long int>>(b, vector<long long int> (c, d)));

//-------------------------------------------------------------------
const ll MAX_V = 1000000;
vvl G = vv(MAX_V, 0, 0, ll);
vvl M = vv(MAX_V, 0, 0, ll);
vvl C = vv(MAX_V, 0, 0, ll);
ll root;
ll parent[30][MAX_V];
vector<ll> depth(MAX_V);

void dfs(ll v, ll p, ll d){
  parent[0][v] = p, depth[v] = d;
  for(int i=0;i<G[v].size();i++) if(G[v][i] != p) dfs(G[v][i], v, d+1);
}
void init(ll V){
  dfs(root, -1, 0);
  for(int k=0;k+1<30;k++){
    for(int v=0;v<V;v++){
      if(parent[k][v]<0) parent[k+1][v] = -1;
      else parent[k+1][v] = parent[k][parent[k][v]];
    }
  }
}
ll lca(int u, int v){
  if(depth[u]>depth[v]) swap(u, v);
  for(int k=0;k<30;k++)if((depth[v]-depth[u])>>k & 1) v = parent[k][v];
  if(u==v) return u;
  for(int k=30-1;k>=0;k--){
    if(parent[k][u] != parent[k][v]){
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}
vector<ll> dist(100001, 0);
vvv t = vvvl(100001, 0, 0, 0);
map<ll, ll> num;
ll l = 0;

void df(ll from, ll now, ll d){
  dist[now] = d;
  num.emplace(now, l),l++;
  ll idx = -1;
  for(int i=0;i<G[now].size();i++){
    if(from==G[now][i]) {
      idx = i;
      continue;
    }
    t[C[now][i]].push_back(vector<ll> {G[now][i], +M[now][i]});
    df(now, G[now][i], d+M[now][i]);
  }
  if(idx==-1) return;
  t[C[now][idx]].push_back(vector<ll> {-1, -M[now][idx]});
}
//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  root = 1;
  ll N, Q, a, b, c, d, x, y, u, v;
  std::cin >> N >> Q;
  for(int i=0;i<N-1;i++){
    std::cin >> a >> b >> c >> d;
    G[a].push_back(b);
    G[b].push_back(a);
    M[a].push_back(d);
    M[b].push_back(d);
    C[a].push_back(c);
    C[b].push_back(c);
  }
  init(N+1);
  df(-1, 1, 0);
  vvv s = vvvl(100001, 0, 0, 0);
  ll m = 0, mm=0;
  for(int i=1;i<t.size();i++){
    s[i].push_back(std::vector<ll> {0, 0});
    for(int j=0;j<t[i].size();j++){
      if(t[i][j][0]>0) s[i].push_back(vector<ll> {num.at(t[i][j][0]), t[i][j][1] + s[i][s[i].size()-1][1]-m}), m=0, mm=0;
      else m+=t[i][j][1], mm--;
    }
  }
  for(int q=0;q<Q;q++){
    std::cin >> x >> y >> u >> v;
    ll p = lca(u, v);
    auto p_x = upper_bound(s[x].begin(), s[x].end(), vector<ll> {num.at(p), 100000000000000});
    auto u_x = upper_bound(s[x].begin(), s[x].end(), vector<ll> {num.at(u), 100000000000000});
    auto v_x = upper_bound(s[x].begin(), s[x].end(), vector<ll> {num.at(v), 100000000000000});
    p_x--,u_x--,v_x--;
    ll sum_uv = (*v_x)[1] + (*u_x)[1] - 2 * (*p_x)[1];
    ll num_uv = u_num + v_num - 2*p_num;
    std::cout << dist[u]+dist[v]-2*dist[p]-sum_uv+num_uv*y << '\n';
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:107:17: error: 'u_num' was not declared in this scope; did you mean 'num'?
  107 |     ll num_uv = u_num + v_num - 2*p_num;
      |                 ^~~~~
      |                 num
a.cc:107:25: error: 'v_num' was not declared in this scope; did you mean 'num'?
  107 |     ll num_uv = u_num + v_num - 2*p_num;
      |                         ^~~~~
      |                         num
a.cc:107:35: error: 'p_num' was not declared in this scope; did you mean 'num'?
  107 |     ll num_uv = u_num + v_num - 2*p_num;
      |                                   ^~~~~
      |                                   num