Language: C++

#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
#define int long long -
struct node{int to,nxt,cost,col;}sq[200200];
int all=0,head[100100];
int n,q,dep[100100],fa[100100][20],cnt[100100];
struct qnode{int col,len,x,id;};
vector<qnode> ask[100100];
ll ans[100100],dis[100100],cdis[100100];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

void add(int u,int v,int col,int w)
{
	all++;sq[all].to=v;sq[all].nxt=head[u];sq[all].col=col;sq[all].cost=w;head[u]=all;
}

void dfs(int u,int fu)
{
	dep[u]=dep[fu]+1;fa[u][0]=fu;
	rep(i,1,19)
		fa[u][i]=fa[fa[u][i]][i-1];
	for (int i=head[u];i;i=sq[i].nxt)
	{
		int v=sq[i].to;
		if (v==fu) continue;
		dis[v]=dis[u]+sq[i].cost;
		dfs(v,u);
	}
}

int LCA(int u,int v)
{
	if (dep[u]<dep[v]) swap(u,v);
	int tmp=dep[u]-dep[v];
	per(i,19,0)
		if ((tmp>>i)&1) u=fa[u][i];
	if (u==v) return u;
	per(i,19,0)
		if (fa[u][i]!=fa[v][i])
		{
			u=fa[u][i];v=fa[v][i];
		}
	return fa[u][0];
}

void dfs1(int u,int fu)
{
	int len=ask[u].size();
	rep(i,0,len-1)
	{
		ans[ask[u][i].id]+=1ll*ask[u][i].x*(dis[u]-cdis[ask[u][i].col]+1ll*ask[u][i].len*cnt[ask[u][i].col]);
	}
	for (int i=head[u];i;i=sq[i].nxt)
	{
		int v=sq[i].to;
		if (v==fu) continue;
		cnt[sq[i].col]++;cdis[sq[i].col]+=sq[i].cost;
		dfs1(v,u);
		cnt[sq[i].col]--;cdis[sq[i].col]-=sq[i].cost;
	}
}

signed main()
{
	n=read();q=read();
	rep(i,1,n-1)
	{
		int u=read(),v=read(),col=read(),w=read();
		add(u,v,col,w);add(v,u,col,w);
	}
	dfs(1,0);
	rep(i,1,q)
	{
		int col=read(),w=read(),u=read(),v=read(),l=LCA(u,v);
		ask[u].push_back((qnode){col,w,1,i});
		ask[v].push_back((qnode){col,w,1,i});
		ask[l].push_back((qnode){col,w,-2,i});
	}
	dfs1(1,0);
	rep(i,1,q) printf("%lld\n",ans[i]);
	return 0;
}

Compiler output:
a.cc:27:23: error: expected unqualified-id before '-' token
   27 | #define int long long -
      |                       ^
a.cc:28:13: note: in expansion of macro 'int'
   28 | struct node{int to,nxt,cost,col;}sq[200200];
      |             ^~~
a.cc:27:23: error: expected unqualified-id before '-' token
   27 | #define int long long -
      |                       ^
a.cc:29:1: note: in expansion of macro 'int'
   29 | int all=0,head[100100];
      | ^~~
a.cc:27:23: error: expected unqualified-id before '-' token
   27 | #define int long long -
      |                       ^
a.cc:30:1: note: in expansion of macro 'int'
   30 | int n,q,dep[100100],fa[100100][20],cnt[100100];
      | ^~~
a.cc:27:23: error: expected unqualified-id before '-' token
   27 | #define int long long -
      |                       ^
a.cc:31:14: note: in expansion of macro 'int'
   31 | struct qnode{int col,len,x,id;};
      |              ^~~
a.cc:27:23: error: expected unqualified-id before '-' token
   27 | #define int long long -
      |                       ^
a.cc:35:1: note: in expansion of macro 'int'
   35 | int read()
      | ^~~
a.cc:27:23: error: expected ',' or '...' before '-' token
   27 | #define int long long -
      |                       ^
a.cc:43:10: note: in expansion of macro 'int'
   43 | void add(int u,int v,int col,int w)
      |          ^~~
a.cc: In function 'void add(long long int)':
a.cc:45:9: error: 'all' was not declared in this scope; did you mean 'll'?
   45 |         all++;sq[all].to=v;sq[all].nxt=head[u];sq[all].col=col;sq[all].cost=w;head[u]=all;
      |         ^~~
      |         ll
a.cc:45:26: error: 'v' was not declared in this scope
   45 |         all++;sq[all].to=v;sq[all].nxt=head[u];sq[all].col=col;sq[all].cost=w;head[u]=all;
      |                          ^
a.cc:45:40: error: 'head' was not declared in this scope
   45 |         all++;sq[all].to=v;sq[all].nxt=head[u];sq[all].col=col;sq[all].cost=w;head[u]=all;
      |                                        ^~~~
a.cc:45:45: error: 'u' was not declared in this scope
   45 |         all++;sq[all].to=v;sq[all].nxt=head[u];sq[all].col=col;sq[all].cost=w;head[u]=all;
      |                                             ^
a.cc:45:60: error: 'col' was not declared in this scope; did you mean 'cosl'?
   45 |         all++;sq[all].to=v;sq[all].nxt=head[u];sq[all].col=col;sq[all].cost=w;head[u]=all;
      |                                                            ^~~
      |                                                            cosl
a.cc:45:77: error: 'w' was not declared in this scope
   45 |         all++;sq[all].to=v;sq[all].nxt=head[u];sq[all].col=col;sq[all].cost=w;head[u]=all;
      |                                                                             ^
a.cc: At global scope:
a.cc:27:23: error: expected ',' or '...' before '-' token
   27 | #define int long long -
      |                       ^
a.cc:48:10: note: in expansion of macro 'int'
   48 | void dfs(int u,int fu)
      |          ^~~
a.cc: In function 'void dfs(long long int)':
a.cc:50:9: error: 'dep' was not declared in this scope; did you mean 'rep'?
   50 |         dep[u]=dep[fu]+1;fa[u][0]=fu;
      |         ^~~
      |         rep
a.cc:50:13: error: 'u' was not declared in this scope
   50 |         dep[u]=dep[fu]+1;fa[u][0]=fu;
      |             ^
a.cc:50:20: error: 'fu' was not declared in this scope
   50 |         dep[u]=dep[fu]+1;fa[u][0]=fu;
      |                    ^~
a.cc:50:26: error: 'fa' was not declared in this scope; did you mean 'fma'?
   50 |         dep[u]=dep[fu]+1;fa[u][0]=fu;
      |                          ^~
      |                          fma
a.cc:27:23: error: expected unqualified-id before '-' token
   27 | #define int long long -
      |                       ^
a.cc:19:34: note: in expansion of macro 'int'
   19 | #define rep(i,a,b) for (register int i=a;i<=b;i++)
      |                                  ^~~
a.cc:51:9: note: in expansion of macro 'rep'
   51 |         rep(i,1,19)
      |         ^~~
a.cc:27:23: error: expected ';' before '-' token
   27 | #define int long long -
      |                       ^
a.cc:19:34: note: in expansion of macro 'int'
   19 | #define rep(i,a,b) for (register int i=a;i<=b;i++)
      |                                  ^~~
a.cc:51:9: note: in expansion of macro 'rep'
   51 |         rep(i,1,19)
      |         ^~~
a.cc:51:13: error: 'i' was not declared in this scope; did you mean 'pi'?
   51 |         rep(i,1,19)
      |             ^
a.cc:19:38: note: in definition of macro 'rep'
   19 | #define rep(i,a,b) for (register int i=a;i<=b;i++)
      |                                      ^
a.cc:19:46: error: expected ')' before ';' token
   19 | #define rep(i,a,b) for (register int i=a;i<=b;i++)
      |                        ~                     ^
a.cc:51:9: note: in expansion of macro 'rep'
   51 |         rep(i,1,19)
      |         ^~~
a.cc:51:13: error: 'i' was not declared in this scope; did you mean 'pi'?
   51 |         rep(i,1,19)
      |             ^
a.cc:19:47: note: in definition of macro 'rep'
   19 | #define rep(i,a,b) for (register int i=a;i<=b;i++)
      |                                               ^
a.cc:27:23: error: expected unqualified-id before '-' token
   27 | #define int long long -
      |                       ^
a.cc:53:14: note: in expansion of macro 'int'
   53 |         for (int i=head[u];i;i=sq[i].nxt)
      |              ^~~
a.cc:27:23: error: expected ';' before '-' token
   27 | #define int long long -
      |                       ^
a.cc:53:14: note: in expansion of macro 'int'
   53 |         for (int i=head[u];i;i=sq[i].nxt)
      |              ^~~
a.cc:53:20: error: 'head' was not declared in this scope
   53 |         for (int i=head[u];i;i=sq[i].nxt)
      |                    ^~~~
a.cc:53:29: error: expected ')' before ';' token
   53 |         for (int i=head[u];i;i=sq[i].nxt)
      |             ~               ^
      |                             )
a.cc: At global scope:
a.cc:27:23: error: expected unqualified-id before '-' token
   27 | #define int long long -
      |                       ^
a.cc:62:1: note: in expansion of macro 'int'
   62 | int LCA(int u,int v)
      | ^~~
a.cc:27:23: error: expected ',' or '...' before '-' token
   27 | #define int long long -
      |                       ^
a.cc:77:11: note: in expansion of macro 'int'
   77 | void dfs1(int u,int fu)
      |           ^~~
a.cc: In function 'void dfs1(long long int)':
a.cc:27:23: error: expected unqualified-id before '-' token
   27 | #define int long long -
      |                       ^
a.cc:79:9: note: in expansion of macro 'int'
   79 |         int len=ask[u].size();
      |         ^~~
a.cc:27:23: error: expected unqualified-id before '-' token
   27 | #define int long long -
      |                       ^
a.cc:19:34: note: in expansion of macro 'int'
   19 | #define rep(i,a,b) for (register int i=a;i<=b;i++)
      |                                  ^~~
a.cc:80:9: note: in expansion of macro 'rep'
   80 |         rep(i,0,len-1)
      |         ^~~
a.cc:27:23: error: expected ';' before '-' token
   27 | #define int long long -
      |                       ^
a.cc:19:34: note: in expansion of macro 'int'
   19 | #define rep(i,a,b) for (register int i=a;i<=b;i++)
      |                                  ^~~
a.cc:80:9: note: in expansion of macro 'rep'
   80 |         rep(i,0,len-1)
      |         ^~~
a.cc:80:13: error: 'i' was not declared in this scope; did you mean 'pi'?
   80 |         rep(i,0,len-1)
      |             ^
a.cc:19:38: note: in definition of macro 'rep'
   19 | #define rep(i,a,b) for (register int i=a;i<=b;i++)
      |                                      ^
a.cc:80:17: error: 'len' was not declared in this scope
   80 |         rep(i,0,len-1)
      |                 ^~~
a.cc:19:45: note: in definition of macro 'rep'
   19 | #define rep(i,a,b) for (register int i=a;i<=b;i++)
      |                                             ^
a.cc:19:46: error: expected ')' before ';' token
   19 | #define rep(i,a,b) for (register int i=a;i<=b;i++)
      |                        ~                     ^
a.cc:80:9: note: in expansion of macro 'rep'
   80 |         rep(i,0,len-1)
      |         ^~~
a.cc:80:13: error: 'i' was not declared in this scope; did you mean 'pi'?
   80 |         rep(i,0,len-1)
      |             ^
a.cc:19:47: note: in definition of macro 'rep'
   19 | #define rep(i,a,b) for (register int i=a;i<=b;i++)
      |                                               ^
a.cc:27:23: error: expected unqualified-id before '-' token
   27 | #define int long long -
      |                       ^
a.cc:84:14: note: in expansion of macro 'int'
   84 |         for (int i=head[u];i;i=sq[i].nxt)
      |              ^~~
a.cc:27:23: error: expected ';' before '-' token
   27 | #define int long long -
      |                       ^
a.cc:84:14: note: in expansion of macro 'int'
   84 |         for (int i=head[u];i;i=sq[i].nxt)
      |              ^~~
a.cc:84:20: error: 'head' was not declared in this scope
   84 |         for (int i=head[u];i;i=sq[i].nxt)
      |                    ^~~~
a.cc:84:25: error: 'u' was not declared in this scope
   84 |         for (int i=head[u];i;i=sq[i].nxt)
      |                         ^
a.cc:84:29: error: expected ')' before ';' token
   84 |         for (int i=head[u];i;i=sq[i].nxt)
      |             ~               ^
      |                             )
a.cc: In function 'int main()':
a.cc:96:9: error: 'n' was not declared in this scope
   96 |         n=read();q=read();
      |         ^
a.cc:96:11: error: 'read' was not declared in this scope; did you mean 'fread'?
   96 |         n=read();q=read();
      |           ^~~~
      |           fread
a.cc:96:18: error: 'q' was not declared in this scope; did you mean 'sq'?
   96 |         n=read();q=read();
      |                  ^
      |                  sq
a.cc:27:23: error: expected unqualified-id before '-' token
   27 | #define int long long -
      |                       ^
a.cc:19:34: note: in expansion of macro 'int'
   19 | #define rep(i,a,b) for (register int i=a;i<=b;i++)
      |