criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef long long int;

const int lg = 21;

int n, q;
int d[100100];
int up[100100][22];
int col[100100];
int cost[100100];
int ans[100100];
int cnt[100100];
int col_dist[100100];
vector<int> adj[100100];
vector<int> weight[100100];
vector<int> color[100100];
vector<int> query[100100];

int lca(int u, int v) {
    if (d[u] > d[v]) swap(u, v);

    int delta = d[v] - d[u];
    for (int i = 0; i <= lg; i++) {
        if (delta & (1 << i)){
            v = up[v][i];
        }
    }

    if (u == v) return u;

    for (int i = lg; i >= 0; i--) {
        if (up[u][i] != up[v][i]) {
            u = up[u][i];
            v = up[v][i];
        }
    }

    return up[u][0];
}

void dfs(int v, int p, int depth) {
    d[v] = depth;
    up[v][0] = p;
    for (int i = 1; i <= lg; i++) {
        up[v][i] = up[up[v][i - 1]][i - 1];
    }
    for (int i = 0; i < (int)adj[v].size(); i++) {
        if (adj[v][i] == p) continue;
        dfs(adj[v][i], v, depth + 1);
    }
}

void solve(int v, int p, int dist) {
    for (int idx: query[v]) {
        int mul = 1;
        if (idx < 0)  {
            mul = -2;
            idx = -idx;
        }
        ans[idx] += mul * (cnt[col[idx]] * cost[idx] - col_dist[col[idx]] + dist);
    }

    for (int i = 0; i < (int)adj[v].size(); i++) {
        if (adj[v][i] == p) continue;
        cnt[color[v][i]]++;
        col_dist[color[v][i]] += weight[v][i];
        solve(adj[v][i], v, dist + weight[v][i]);
        cnt[color[v][i]]--;
        col_dist[color[v][i]] -= weight[v][i];
    }
}



int main() {
    scanf("%d %d", &n, &q);

    for (int i = 0; i < n - 1; i++) {
        int u, v, c;
        int w;
        scanf("%d %d %d %d", &u, &v, &c, &w);
        adj[u].push_back(v);
        adj[v].push_back(u);
        color[u].push_back(c);
        color[v].push_back(c);
        weight[u].push_back(w);
        weight[v].push_back(w);
    }

    dfs(1, 0, 0);
    // for (int j = 1; j <= lg; j++) {
    //     for (int i = 1; i <= n; i++) {
    //         up[i][j] = up[up[i - 1][j - 1]][j - 1];
    //     }
    // }

    for (int i = 1; i <= q; i++) {
        int u, v;
        scanf("%d %d %d %d", &col[i], &cost[i], &u, &v);
        query[u].push_back(i);
        query[v].push_back(i);
        query[lca(u, v)].push_back(-i);
        // printf("LCA %d\n", lca(u, v));
    }

    solve(1, 0, 0);

    for (int i = 1; i <= q; i++) {
        printf("%d\n", ans[i]);
    }
}

Compiler output:
a.cc:5:19: error: declaration does not declare anything [-fpermissive]
    5 | typedef long long int;
      |                   ^~~
Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<queue>
#include<utility>
#include<algorithm>
#include<math.h>
using namespace std;
priority_queue<pair<int,int> > Q;
int n,q;
int tot=0;
int to[300000],w[300000],color[300000],ver[300000],next[300000];
void add(int a,int b,int c,int d){
	to[++tot]=b;
	w[tot]=d;
	color[tot]=c;
	next[tot]=ver[a];
	ver[a]=tot;
}
int dj(int chg,int chgd,int start,int end){
	int dis[100005];
	int book[100005];
	memset(dis,0x3f,sizeof(dis));
	memset(book,0,sizeof(book));
	dis[start]=0;
	Q.push(make_pair(0,start));
	while(!Q.empty()){
		int now=Q.top().second;
		Q.pop();
		if(book[now]) continue;
		book[now]=1;
		for(int i=ver[now];i;i=next[i]){
			int tv,te;
			tv=to[i];
			te=w[i];
			if(color[i]==chg) te=chgd;
			//cout<<dis[tv];
			//cout<<data[2][i]<<' '<<i<<endl;
			if(te+dis[now]<dis[tv]){
				//cout<<te+dis[now]<<endl;
				dis[tv]=te+dis[now];
				Q.push(make_pair(-dis[tv],tv));
			}
		}
	}
	return dis[end];
}
int main(){
	cin>>n>>q;
	int a,b,c,d;
	for(int i=1;i<=n;i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		add(a,b,c,d);
		add(b,a,c,d);
	}
	for(int i=1;i<=q,i++){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		cout<<dj(a,b,c,d)<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'void add(int, int, int, int)':
a.cc:18:9: error: reference to 'next' is ambiguous
   18 |         next[tot]=ver[a];
      |         ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:13:52: note:                 'int next [300000]'
   13 | int to[300000],w[300000],color[300000],ver[300000],next[300000];
      |                                                    ^~~~
a.cc: In function 'int dj(int, int, int, int)':
a.cc:33:40: error: reference to 'next' is ambiguous
   33 |                 for(int i=ver[now];i;i=next[i]){
      |                                        ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:13:52: note:                 'int next [300000]'
   13 | int to[300000],w[300000],color[300000],ver[300000],next[300000];
      |                                                    ^~~~
a.cc: In function 'int main()':
a.cc:57:29: error: expected ';' before ')' token
   57 |         for(int i=1;i<=q,i++){
      |                             ^
      |                             ;
Language: C++

#include<iostream>
#include<vector>
#define ll long long
#pragma GCC diagnostic error "-std=c++11"
using namespace std;
const int mxn=100005;
#define int ll 
struct vertex{
	int nxt,col;ll dist;
	vertex(){}
	vertex(int _x,int _c,int _d):nxt(_x),col(_c),dist(_d){}
};
struct query{
	int id,x,y,f;
	query(){}
	query(int _i,int _x,int _y,int _f):id(_i),x(_x),y(_y),f(_f){}
};
vector<vertex> g[mxn<<1];
int n,m;
ll ans[mxn],cnt[mxn],dis[mxn],dep[mxn];
vector<query> q[mxn];
int fa[mxn][22];
inline void predfs(int u,int par,ll dp){
	fa[u][0]=par;dep[u]=dp;
	for(vertex v:g[u]){
		if(v.nxt==par) continue;
		predfs(v.nxt,u,dp+1);
	}
}
inline void parinit(){
	for(int i=1;i<=19;++i) for(int j=1;j<=n;++j) fa[i][j]=fa[i-1][fa[i-1][j]];
}
inline int lca(int x,int y){
	if(dep[x]>dep[y]) swap(x,y);
	int step=dep[y]-dep[x],i;
	for(i=19;~i;--i) if(step&(1<<i)) y=fa[y][i];
	for(i=19;~i;--i) if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
inline void dfs(int u,int par,ll dist){
	int i;
	for(i=0;i<q[u].size();++i){
		int id=q[u][i].id,a=q[u][i].x,b=q[u][i].y,f=q[u][i].f;
		ans[id]+=1ll*f*(dist-dis[a]+cnt[a]*b);
	}
	for(vertex v:g[u]){
		int vv=v.nxt,c=v.col,ds=v.dist;
		if(vv==par) continue;
		++cnt[c],dis[c]+=ds;
		dfs(vv,u,dist+ds);
		--cnt[c],dis[c]-=ds;
	}
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	int i,j,x,y,col,len,u,v;
	for(i=1;i<n;++i){
		cin>>x>>y>>col>>len;
		g[x].push_back(vertex(y,col,len));
		g[y].push_back(vertex(x,col,len));
	}
	predfs(1,0,0);
	parinit();
	for(i=1;i<=m;++i){
		cin>>x>>y>>u>>v;
		q[u].push_back(query(i,x,y,1));
		q[v].push_back(query(i,x,y,1));
		int l=lca(u,v);
		q[l].push_back(query(i,x,y,-2));
	}
	dfs(1,0,0);
	for(i=1;i<=m;++i) cout<<ans[i]<<endl;
}

Compiler output:
a.cc:4:30: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    4 | #pragma GCC diagnostic error "-std=c++11"
      |                              ^~~~~~~~~~~~
cc1plus: error: '::main' must return 'int'
Language: C++

#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
int block;
int first[2000010], next[4000010], tail[4000010], ce[4000010], de[4000010], c[2000010], d[2000010], f[2000010][30], dep[2000010];
int x1[1000010], x3[1000010], x4[1000010], t[1000010], x5[1000010];
long long x2[1000010];
int n, Q, edge;
int dfs_clock, arr[2000010], start[2000010], end[2000010];
long long ans[2000010];
inline void addedge(int u, int v, int color, int dist) {
	edge++;
	next[edge] = first[u];
	first[u] = edge;
	tail[edge] = v;
	ce[edge] = color;
	de[edge] = dist;
}
void dfs(int u, int p) {
	dep[u] = dep[p] + 1;
	f[u][0] = p;
	for (int i = 1;i <= 20;i++) f[u][i] = f[f[u][i - 1]][i - 1];

	arr[++dfs_clock] = u;
	start[u] = dfs_clock;
	for (int e = first[u];e;e = next[e]) if (tail[e] != p) {
		int v = tail[e];
		c[v] = ce[e];
		d[v] = de[e];
		dfs(v, u);
	}
	arr[++dfs_clock] = u;
	end[u] = dfs_clock;
}
inline int lca(int u, int v) {
	if (dep[u] < dep[v]) std::swap(u, v);
	for (int i = 20;i >= 0;i--) if (dep[f[u][i]] >= dep[v]) u = f[u][i];
	if (u == v) return u;
	for (int i = 20;i >= 0;i--) if (f[u][i] != f[v][i]) {
		u = f[u][i];
		v = f[v][i];
	}
	return f[u][0];
}
bool comp(int u, int v) {
	if (x3[u] / block == x3[v] / block)
		return x4[u] < x4[v];
	else
		return x3[u] / block < x3[v] / block;
}
bool status[200010];
int count[200010];
long long sum[200010], sigma;
inline void trigger(int u) {
	if (!status[u]) {
		status[u] = true;
		sigma += d[u];
		sum[c[u]] += d[u];
		count[c[u]]++;
	} else {
		status[u] = false;
		sigma -= d[u];
		sum[c[u]] -= d[u];
		count[c[u]]--;
	}
}
int main() {
	edge = 0;
	scanf("%d%d", &n, &Q);
	for (int i = 1;i < n;i++) {
		int u, v, color, dist;
		scanf("%d%d%d%d", &u, &v, &color, &dist);
		addedge(u, v, color, dist);
		addedge(v, u, color, dist);
	}
	dfs_clock = 0;
	dfs(1, 0);
	for (int i = 1;i <= Q;i++) {
		int u, v;
		scanf("%d%lld%d%d", &x1[i], &x2[i], &u, &v);
		if (start[u] > start[v]) std::swap(u, v);
		x5[i] = lca(u, v);
		if (x5[i] == u || x5[i] == v) {
			x3[i] = last[v];
			x4[i] = last[u] - 1;
		} else {
			x3[i] = end[u];
			x4[i] = start[v];
		}
	}
	for (int i = 1;i <= Q;i++) t[i] = i;
	block = sqrt(dfs_clock);
	std::sort(t + 1, t + 1 + Q, comp);
	sigma = 0;
	int l = 1, r = 0;
	for (int i = 1;i <= Q;i++) {
		int u = t[i];
		while (l > x3[u]) {
			l--;
			trigger(arr[l]);
		}
		while (r < x4[u]) {
			r++;
			trigger(arr[r]);
		}
		while (l < x3[u]) {
			trigger(arr[l]);
			l++;
		}
		while (r > x4[u]) {
			trigger(arr[r]);
			r--;
		}
		//trigger(x5[u]);
		ans[u] = sigma - sum[x1[u]] + count[x1[u]] * x2[u];
		//trigger(x5[u]);
	}
	for (int i = 1;i <= Q;i++) printf("%lld\n", ans[i]);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:85:33: error: 'last' was not declared in this scope
   85 |                         x3[i] = last[v];
      |                                 ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10,LOG=21;
int up[maxn][22],tin[maxn],tout[maxn],timer;
int n,T;
struct edge{
    int u,col,w;
};
vector<edge> a[maxn];
void dfs(int nod,int pa){
    ++timer;
    tin[nod]=timer;
    up[nod][0]=pa;
    for(int i=1;i<=LOG;i++){
        up[nod][i]=up[up[nod][i-1]][i-1];
    }
    for(auto i:a[nod]){
        if(i.u!=pa){
            dfs(i.u,nod);
        }
    }
    tout[nod]=++timer;
    return;
}
bool ancestor(int u,int v){
    return tin[u]<=tin[v]&&tout[u]>=tout[v];
}
int lca(int u,int v){
    if(ancestor(u,v))
        return u;
    if(ancestor(v,u))
        return v;
    for(int i=LOG;i>=1;i--){
        if(!ancestor(up[u][i],v))
            u=up[u][i];
    }
    return up[u][0];
}
int ans[maxn];
map<int,int> dp,ct;
vector<int> q[maxn];
struct query{
    int col,w;
}b[maxn];
void dfs_2(int nod,int pa,int cur){
    for(int i:q[nod]){
        int f=((i<0)?-2:1);
        i=abs(i);
        ans[i]+=(f*((ct[b[i].col]*b[i].w)-dp[b[i].col]+dis[nod]+cur));

        /**
        if(i<0){
            ans[-i]-=2*dis[nod];
            ans[-i]+=2*dp[b[-i].col];
            ans[-i]-=2*(ct[b[-i].col]*b[-i].w);
        }
        else{
            ans[i]+=dis[nod];
            ans[i]-=dp[b[i].col];
            ans[i]+=(ct[b[i].col]*b[i].w);
        }

        **/
    }
    for(auto i:a[nod]){
        if(i.u!=pa){
            dp[i.col]+=i.w;
            ct[i.col]++;
            dfs_2(i.u,nod,cur+i.w);
            dp[i.col]-=i.w;
            ct[i.col]--;
        }
    }
    return;
}

int main(){
    tout[0]=1e9;
    scanf("%d%d",&n,&T);
    int x,y,z,w;
    for(int i=1;i<n;i++){
        scanf("%d%d%d%d",&x,&y,&z,&w);
        a[x].push_back({y,z,w});
        a[y].push_back({x,z,w});
    }
    dfs(1,0);
    for(int i=1;i<=T;i++){
        scanf("%d%d%d%d",&b[i].col,&b[i].w,&x,&y);
        q[x].push_back(i);
        q[y].push_back(i);
        q[lca(x,y)].push_back(-i);
    }
    dfs_2(1,0,0);
    for(int i=1;i<=T;i++){
        printf("%d\n",ans[i]);
    }

}


Compiler output:
a.cc: In function 'void dfs_2(int, int, int)':
a.cc:49:56: error: 'dis' was not declared in this scope; did you mean 'div'?
   49 |         ans[i]+=(f*((ct[b[i].col]*b[i].w)-dp[b[i].col]+dis[nod]+cur));
      |                                                        ^~~
      |                                                        div
Language: C++

# include <iostream>
# include <vector>
# include <algorithm>

using namespace std;

const int N = 1e5 + 100;
const int B = 20;
struct edge{ int f, s,clr, dst; };

int n, q, sq, depth[N], dist[N];
int LCA[N][B+1], cl[N], ds[N];

vector < edge > gr[N];
vector < int > ver[N], cer[N], crn( N,0 ),cnt(N, 0);

void dfs1( int v, int p )
{
    if( depth[v] % sq == 1 ){
        ver[v] = cnt;
        cer[v] = crn;
        /*
        fill( cnt.begin(), cnt.end(), 0 );
        fill( crn.begin(), crn.end(), 0 );
        */
    }
    LCA[v][0] = p;
    for( int i = 1; i <= B; i ++ ){
        LCA[v][i] = LCA[LCA[v][i-1]][i-1];
    }
    for( auto e: gr[v] ){
        if( e.s == p )
            continue;
        cl[e.s] = e.clr;
        ds[e.s] = e.dst;
        dist[e.s] = dist[e.f] + e.dst;
        depth[e.s] = depth[e.f] + 1;
        cnt[e.clr] ++;
        crn[e.clr] += e.dst;
        dfs1( e.s, e.f );
        cnt[e.clr] --;
        crn[e.clr] -= e.dst;
    }
}

int lca( int a, int b )
{
    if( depth[a] < depth[b] ) swap( a, b );
    for( int i = B; i >= 0; i -- ){
        if( depth[ LCA[a][i] ] >= depth[b] ){
            a = LCA[a][i];
        }
    }
    for ( int i = B; i >= 0; i -- ){
        if( LCA[a][i] != LCA[b][i] ){
            a = LCA[a][i];
            b = LCA[b][i];
        }
    }
    if( a != b ) a = LCA[a][0];
    return a;
}

pair < int, int > get( int v, int x )
{
    pair < int, int > ret = {0,0};
    if( ver[v].size() != 0 ){
        ret.first = ver[v][x];
        ret.second = cer[v][x];
    }
    else{
        if( cl[v] == x ){
            ret.first++;
            ret.second+= ds[v];
        }
        pair < int, int > ret1 = get( LCA[v][0], x );
        ret.first += ret1.first;
        ret.second += ret1.second;
        return ret;
    }
    return ret;
}

int main()
{
    ios_base::sync_with_stdio( false );

    cin >> n >> q;
    for( int i = 1; i < n;i  ++ ){
        edge e;
        cin >> e.f >> e.s >> e.clr >> e.dst;
        gr[e.f].push_back( e );
        swap( e.f, e.s );
        gr[e.f].push_back( e );
    }

    sq = sqrt( n );
    depth[1] = 1;
    dfs1( 1,0 );

    while( q-- ){
        int x, y, v, u;
        cin >> x >> y >> v >> u;
        int lc = lca( v, u );
        int D = dist[v] + dist[u] - 2*dist[ lc ];

        auto r1 = get( v, x );
        auto r2 = get( u, x );
        auto r3 = get( lc, x );
        r1.first += r2.first - 2*r3.first;
        r1.second += r2.second - 2*r3.second;
        cout << D-r2.second+r1.first*y << endl;
        }

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:97:10: error: 'sqrt' was not declared in this scope; did you mean 'sq'?
   97 |     sq = sqrt( n );
      |          ^~~~
      |          sq
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define N 100005
int st[N],nd[N],a[N];
int pos[N],dfn[N],cnt,sum[N][2],s1;
int fa[N][20],dep[N],ans[N],n,m,an;
int g1[N][2];
bool f[N];
struct mzls
{
	int l,r,id,aa,bb;
	bool p;
}a1[N];
struct node
{
	int to,co,ct;
	node(){}
	node(int xx,int yy,int zz)
	{
		to=xx,co=yy,ct=zz;
	}
};
vector<node>g[N];
inline bool cmp(mzls x,mzls y)
{
	if(pos[x.l]!=pos[y.l])
		return pos[x.l]<pos[y.l];
	return x.r<y.r;
}
map<int,int>mp;
inline void dfs(int x)
{
	dfn[++cnt]=x;
	st[x]=cnt;
	dep[x]=dep[fa[x][0]]+1;
	for(int i=1;i<20;i++)
		fa[x][i]=fa[fa[x][i-1]][i-1];
	int l1=g[x].size();
	for(int i=0;i<l1;i++)
	{
		int v=g[x][i].to,co=g[x][i].co,ct=g[x][i].ct;
		if(v==fa[x][0])
			continue;
		fa[v][0]=x;
		g1[v][0]=co,g1[v][1]=ct;
		dfs(v);
	}
	dfn[++cnt]=x;
	nd[x]=cnt;
}
inline int LCA(int x,int y)
{
	if(dep[x]<dep[y])
		swap(x,y);
	for(int i=19;i>=0;i--)
		if(dep[fa[x][i]]>=dep[y])
			x=fa[x][i];
	if(x==y)
		return x;
	for(int i=19;i>=0;i--)
		if(fa[x][i]!=fa[y][i])
		{
			x=fa[x][i];
			y=fa[y][i];
		}
	return fa[x][0];
}
inline void modify(int x)
{
	if(!f[x])
	{
		sum[g1[x][0]][0]++;
		sum[g1[x][0]][1]+=g1[x][1];
		s1+=g1[x][1];
		f[x]=1;
	}
	else
	{
		sum[g1[x][0]][0]--;
		sum[g1[x][0]][1]-=g1[x][1];
		s1-=g1[x][1];
		f[x]=0;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)
	{
		int x,y,x1,y1;
		scanf("%d%d%d%d",&x,&y,&x1,&y1);
		g[x].push_back(node(y,x1,y1));
		g[y].push_back(node(x,x1,y1));
	}
	dfs(1);
	int d=sqrt(n);
	for(int i=1;i<=2*n;i++)
		pos[i]=(i-1)/d;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d%d%d",&a1[i].aa,&a1[i].bb,&a1[i].l,&a1[i].r);
		if(st[a1[i].l]>st[a1[i].r])
			swap(a1[i].l,a1[i].r);
		if(nd[a1[i].l]>st[a1[i].r])
		{
			x=ed[a1[i].l];
			y=st[a1[i].r];
			a1[i].p=0;
		}
		else
		{
			x=st[a1[i].l]+1;
			y=st[a1[i].r];
			a1[i].p=1;
		}
		a1[i].l=x;
		a1[i].r=y;
		a1[i].id=i;
	}
	sort(a1+1,a1+m+1,cmp);
	int l1=1,r1=0;
	for(int i=1;i<=m;i++)
	{
		while(l1>a1[i].l)
			modify(dfn[--l1]);
		while(l1<a1[i].l)
			modify(dfn[l1++]);
		while(r1<a1[i].r)
			modify(dfn[++r1]);
		while(r1>a1[i].r)
			modify(dfn[r1--]);
		int lc=LCA(dfn[l1],dfn[r1]);
		//if(a1[i].p)
		//	modify(lc);
		ans[a1[i].id]=s1-sum[a1[i].aa][1]+sum[a1[i].aa][0]*a1[i].bb;
		//if(a1[i].p)
		//	modify(lc);
	}
	for(int i=1;i<=m;i++)
		printf("%d\n",ans[i]);
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:107:27: error: 'ed' was not declared in this scope; did you mean 'd'?
  107 |                         x=ed[a1[i].l];
      |                           ^~
      |                           d
Language: C++

#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
#define N 400005
int st[N],nd[N],a[N];
int pos[N],dfn[N],cnt,sum[N][2],s1;
int fa[N][20],dep[N],ans[N],n,m,an;
int g1[N][2];
bool f[N];
struct mzls
{
	int l,r,id,aa,bb;
	bool p;
}a1[N];
struct node
{
	int to,co,ct;
	node(){}
	node(int xx,int yy,int zz)
	{
		to=xx,co=yy,ct=zz;
	}
};
vector<node>g[N];
bool operator<(mzls a,mzls b)
{
	return pos[a.l]==pos[b.l]?a.r<b.r:a.l<b.l;
}
inline void dfs(int x)
{
	dfn[++cnt]=x;
	st[x]=cnt;
	dep[x]=dep[fa[x][0]]+1;
	for(int i=1;i<20;i++)
		fa[x][i]=fa[fa[x][i-1]][i-1];
	int l1=g[x].size();
	for(int i=0;i<l1;i++)
	{
		int v=g[x][i].to,co=g[x][i].co,ct=g[x][i].ct;
		if(v==fa[x][0])
			continue;
		fa[v][0]=x;
		g1[v][0]=co,g1[v][1]=ct;
		dfs(v);
	}
	dfn[++cnt]=x;
	nd[x]=cnt;
}
inline int LCA(int x,int y)
{
	if(dep[x]<dep[y])
		swap(x,y);
	for(int i=19;i>=0;i--)
		if(dep[fa[x][i]]>=dep[y])
			x=fa[x][i];
	if(x==y)
		return x;
	for(int i=19;i>=0;i--)
		if(fa[x][i]!=fa[y][i])
		{
			x=fa[x][i];
			y=fa[y][i];
		}
	return fa[x][0];
}
inline void modify(int x)
{
	if(!f[x])
	{
		sum[g1[x][0]][0]++;
		sum[g1[x][0]][1]+=g1[x][1];
		s1+=g1[x][1];
		f[x]=1;
	}
	else
	{
		sum[g1[x][0]][0]--;
		sum[g1[x][0]][1]-=g1[x][1];
		s1-=g1[x][1];
		f[x]=0;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)
	{
		int x,y,x1,y1;
		scanf("%d%d%d%d",&x,&y,&x1,&y1);
		g[x].push_back(node(y,x1,y1));
		g[y].push_back(node(x,x1,y1));
	}
	dfs(1);
	int d=sqrt(n);
	for(int i=1;i<=n;i++)
		pos[i]=i/d;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d%d%d",&a1[i].aa,&a1[i].bb,&a1[i].l,&a1[i].r);
		int lc=LCA(a1[i].l,a1[i].r);
		if(lc==a1[i].l||lc=a1[i].r)
		{
			if(lc==a1[i].r)
				swap(a1[i].l,a1[i].r);
			x=st[a1[i].l]+1;
			y=st[a1[i].r];
			a1[i].p=0;
		}
		else
		{
			if(st[a1[i].l]>st[a1[i].r])
				swap(a1[i].l,a1[i].r);
			x=nd[a1[i].l];
			y=st[a1[i].r];
			a1[i].p=1;
		}
		a1[i].l=x;
		a1[i].r=y;
		a1[i].id=i;
	}
	sort(a1+1,a1+m+1);
	int l1=1,r1=0;
	for(int i=1;i<=m;i++)
	{
		while(l1>a1[i].l)
			modify(dfn[--l1]);
		while(l1<a1[i].l)
			modify(dfn[l1++]);
		while(r1<a1[i].r)
			modify(dfn[++r1]);
		while(r1>a1[i].r)
			modify(dfn[r1--]);
		//int lc=LCA(dfn[l1],dfn[r1]);
		//if(a1[i].p)
		//	modify(lc);
		ans[a1[i].id]=s1-sum[a1[i].aa][1]+sum[a1[i].aa][0]*a1[i].bb;
		//if(a1[i].p)
		//	modify(lc);
	}
	for(int i=1;i<=m;i++)
		printf("%d\n",ans[i]);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:104:31: error: lvalue required as left operand of assignment
  104 |                 if(lc==a1[i].l||lc=a1[i].r)
      |                    ~~~~~~~~~~~^~~~
Language: C++

#include<cstdio>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
const int MAXN = 100000;
int BLOCK;
struct node
{
	int to,co,ct;
	node(){}
	node(int xx,int yy,int zz)
	{
		to=xx,co=yy,ct=zz;
	}
};
vector<node>g[MAXN];
void addedge(int u, int v, int c, int d) {
	g[u].push_back(node(v,c,d));
	g[v].push_back(node(u,c,d));
}
int clr[MAXN + 5], dis[MAXN + 5];
int fa[MAXN + 5][20], dep[MAXN + 5];
int dfn[2*MAXN + 5], fir[MAXN + 5], bac[MAXN + 5], dcnt = 0;
void dfs(int x, int pre) {
	dfn[++dcnt] = x, fir[x] = dcnt;
	fa[x][0] = pre, dep[x] = dep[pre] + 1;
	for(int i=1;i<20;i++)
		fa[x][i] = fa[fa[x][i-1]][i-1];
	for(int i=0;i<g[x].size();i++)
	{
		int v=g[x][i].to;
		if( v != pre ) {
			dfs(v, x);
			clr[v] = g[x][i].co, dis[v] = g[x][i].ct;
		}
	}
	dfn[++dcnt] = x, bac[x] = dcnt;
}
int lca(int u, int v) {
	if( dep[u] < dep[v] ) swap(u, v);
	for(int i=19;i>=0;i--)
		if( dep[fa[u][i]] >= dep[v] )
			u = fa[u][i];
	if( u == v ) return u;
	for(int i=19;i>=0;i--)
		if( fa[u][i] != fa[v][i] )
			u = fa[u][i], v = fa[v][i];
	return fa[u][0];
}
struct query{
	int le, ri, num;
	int x, y;
}qry[MAXN + 5];
bool operator < (query a, query b) {
	return (a.le/BLOCK == b.le/BLOCK) ? a.ri < b.ri : a.le < b.le;
}
int nwres, cnt[MAXN + 5], tag[MAXN + 5];
int sum[MAXN + 5], ans[MAXN + 5];
void update(int x) {
	int y = dfn[x];
	if( tag[y] )
		cnt[clr[y]]--, sum[clr[y]] -= dis[y], nwres -= dis[y];
	else cnt[clr[y]]++, sum[clr[y]] += dis[y], nwres += dis[y];
	tag[y] ^= 1;
}
int main() {
	int N, Q; scanf("%d%d", &N, &Q);
	for(int i=1;i<N;i++) {
		int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
		addedge(a, b, c, d);
	}
	dfs(1, 0);
	BLOCK=sqrt(n);
	for(int i=1;i<=Q;i++) {
		int x, y, u, v; scanf("%d%d%d%d", &x, &y, &u, &v);
		int l = lca(u, v);
		if( l == u || l == v ) {
			if( l == v ) swap(u, v);
			qry[i].le = fir[u] + 1, qry[i].ri = fir[v];
		}
		else {
			if( fir[u] > fir[v] ) swap(u, v);
			qry[i].le = bac[u], qry[i].ri = fir[v];
		}
		qry[i].num = i, qry[i].x = x, qry[i].y = y;
	}
	sort(qry + 1, qry + Q + 1);
	int l = 1, r = 0;
	for(int i=1;i<=Q;i++) {
		while( l > qry[i].le ) update(--l);
		while( r < qry[i].ri ) update(++r);
		while( l < qry[i].le ) update(l++);
		while( r > qry[i].ri ) update(r--);
		ans[qry[i].num] = nwres - sum[qry[i].x] + cnt[qry[i].x]*qry[i].y;
	}
	for(int i=1;i<=Q;i++)
		printf("%d\n", ans[i]);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:74:20: error: 'n' was not declared in this scope
   74 |         BLOCK=sqrt(n);
      |                    ^
Language: C++

#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int MAXN = 100000;
int BLOCK;
struct node
{
	int to,co,ct;
	node(){}
	node(int xx,int yy,int zz)
	{
		to=xx,co=yy,ct=zz;
	}
};
vector<node>g[MAXN];
void addedge(int u, int v, int c, int d) {
	g[u].push_back(node(v,c,d));
	g[v].push_back(node(u,c,d));
}
int clr[MAXN + 5], dis[MAXN + 5];
int fa[MAXN + 5][20], dep[MAXN + 5];
int dfn[2*MAXN + 5], fir[MAXN + 5], bac[MAXN + 5], dcnt = 0;
void dfs(int x, int pre) {
	dfn[++dcnt] = x, fir[x] = dcnt;
	fa[x][0] = pre, dep[x] = dep[pre] + 1;
	for(int i=1;i<20;i++)
		fa[x][i] = fa[fa[x][i-1]][i-1];
	for(int i=0;i<g[x].size();i++)
	{
		int v=g[x][i].to;
		if( v != pre ) {
			dfs(v, x);
			clr[v] = g[x][i].co, dis[v] = g[x][i].ct;
		}
	}
	dfn[++dcnt] = x, bac[x] = dcnt;
}
int lca(int u, int v) {
	if( dep[u] < dep[v] ) swap(u, v);
	for(int i=19;i>=0;i--)
		if( dep[fa[u][i]] >= dep[v] )
			u = fa[u][i];
	if( u == v ) return u;
	for(int i=19;i>=0;i--)
		if( fa[u][i] != fa[v][i] )
			u = fa[u][i], v = fa[v][i];
	return fa[u][0];
}
struct query{
	int le, ri, num;
	int x, y;
}qry[MAXN + 5];
bool operator < (query a, query b) {
	return (a.le/BLOCK == b.le/BLOCK) ? a.ri < b.ri : a.le < b.le;
}
int nwres, cnt[MAXN + 5], tag[MAXN + 5];
int sum[MAXN + 5], ans[MAXN + 5];
void update(int x) {
	int y = dfn[x];
	if( tag[y] )
		cnt[clr[y]]--, sum[clr[y]] -= dis[y], nwres -= dis[y];
	else cnt[clr[y]]++, sum[clr[y]] += dis[y], nwres += dis[y];
	tag[y] ^= 1;
}
int main() {
	int N, Q; scanf("%d%d", &N, &Q);
	for(int i=1;i<N;i++) {
		int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
		addedge(a, b, c, d);
	}
	dfs(1, 0);
	BLOCK=sqrt(n);
	for(int i=1;i<=Q;i++) {
		int x, y, u, v; scanf("%d%d%d%d", &x, &y, &u, &v);
		int l = lca(u, v);
		if( l == u || l == v ) {
			if( l == v ) swap(u, v);
			qry[i].le = fir[u] + 1, qry[i].ri = fir[v];
		}
		else {
			if( fir[u] > fir[v] ) swap(u, v);
			qry[i].le = bac[u], qry[i].ri = fir[v];
		}
		qry[i].num = i, qry[i].x = x, qry[i].y = y;
	}
	sort(qry + 1, qry + Q + 1);
	int l = 1, r = 0;
	for(int i=1;i<=Q;i++) {
		while( l > qry[i].le ) update(--l);
		while( r < qry[i].ri ) update(++r);
		while( l < qry[i].le ) update(l++);
		while( r > qry[i].ri ) update(r--);
		ans[qry[i].num] = nwres - sum[qry[i].x] + cnt[qry[i].x]*qry[i].y;
	}
	for(int i=1;i<=Q;i++)
		printf("%d\n", ans[i]);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:73:20: error: 'n' was not declared in this scope
   73 |         BLOCK=sqrt(n);
      |                    ^
a.cc:73:15: error: 'sqrt' was not declared in this scope
   73 |         BLOCK=sqrt(n);
      |               ^~~~
Language: C++

#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
#define N 400005
int st[N],nd[N],a[N];
int pos[N],dfn[N],cnt,sum[N][2],s1;
int fa[N][20],dep[N],ans[N],n,m,an;
int g1[N][2];
bool f[N];
struct mzls
{
	int l,r,id,aa,bb;
	bool p;
}a1[N];
struct node
{
	int to,co,ct;
	node(){}
	node(int xx,int yy,int zz)
	{
		to=xx,co=yy,ct=zz;
	}
};
vector<node>g[N];
inline bool cmp(mzls x,mzls y)
{
	if(pos[x.l]!=pos[y.l])
		return pos[x.l]<pos[y.l];
	return x.r<y.r;
}
inline void dfs(int x)
{
	dfn[++cnt]=x;
	st[x]=cnt;
	dep[x]=dep[fa[x][0]]+1;
	for(int i=1;i<20;i++)
		fa[x][i]=fa[fa[x][i-1]][i-1];
	int l1=g[x].size();
	for(int i=0;i<l1;i++)
	{
		int v=g[x][i].to,co=g[x][i].co,ct=g[x][i].ct;
		if(v==fa[x][0])
			continue;
		fa[v][0]=x;
		g1[v][0]=co,g1[v][1]=ct;
		dfs(v);
	}
	dfn[++cnt]=x;
	nd[x]=cnt;
}
inline int LCA(int x,int y)
{
	if(dep[x]<dep[y])
		swap(x,y);
	for(int i=19;i>=0;i--)
		if(dep[fa[x][i]]>=dep[y])
			x=fa[x][i];
	if(x==y)
		return x;
	for(int i=19;i>=0;i--)
		if(fa[x][i]!=fa[y][i])
		{
			x=fa[x][i];
			y=fa[y][i];
		}
	return fa[x][0];
}
inline void modify(int x)
{
	if(!f[x])
	{
		sum[g1[x][0]][0]++;
		sum[g1[x][0]][1]+=g1[x][1];
		s1+=g1[x][1];
		f[x]=1;
	}
	else
	{
		sum[g1[x][0]][0]--;
		sum[g1[x][0]][1]-=g1[x][1];
		s1-=g1[x][1];
		f[x]=0;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++)
	{
		int x,y,x1,y1;
		scanf("%d%d%d%d",&x,&y,&x1,&y1);
		g[x].push_back(node(y,x1,y1));
		g[y].push_back(node(x,x1,y1));
	}
	dfs(1);
	int d=sqrt(n);
	for(int i=1;i<=n;i++)
		pos[i]=i/d;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d%d%d",&a1[i].aa,&a1[i].bb,&a1[i].l,&a1[i].r);
		int lc=LCA(a1[i].l,a1[i].r);
		if(nd[a1[i].l]>st[a1[i].r])
		{
			x=st[a1[i].r]+1;
			y=st[a1[i].l];
			a1[i].p=0;
		}
		else
		{
			if(st[a1[i].l]>st[a1[i].r])
				swap(a1[i].l,a1[i].r);
			x=nd[a1[i].l];
			y=st[a1[i].r];
			a1[i].p=1;
		}
		a1[i].l=x;
		a1[i].r=y;
		a1[i].id=i;
	}
	sort(a1+1,a1+m+1,cmp);
	int l1=1,r1=0;
	for(int i=1;i<=m;i++)
	{
		while(l1>a1[i].l)
			modify(dfn[--l1]);
		while(l1<a1[i].l)
			modify(dfn[l1++]);
		while(r1<a1[i].r)
			modify(dfn[++r1]);
		while(r1>a1[i].r)
			modify(dfn[r1--]);
		int lc=LCA(dfn[l1],dfn[r1]);
		//if(a1[i].p)
		//	modify(lc);
		ans[a1[i].id]=s1-sum[a1[i].aa][1]+sum[a1[i].aa][0]*a1[i].bb;
		//if(a1[i].p)
		//	modify(lc);
	}
	for(int i=1;i<=m;i++)
		printf("%d\n",ans[i]);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:97:15: error: 'sqrt' was not declared in this scope; did you mean 'st'?
   97 |         int d=sqrt(n);
      |               ^~~~
      |               st
Language: C++

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, n) for (int i = a, _n = n; i <= _n; ++i)
#define DREP(i, a, n) for (int i = a, _n = n; i >= _n; --i)
#define FOR(i, a, n) for (int i = a, _n = n; i < _n; ++i)
#define EREP(i, a) for (int i = first[a]; i; i = edge[i].nxt)
#define debug(x) cout << #x << " = " << x << endl

const int SIZE = 100005;

int n, q;

int first[SIZE], ecnt;
struct Edge {
  int v, d, c, nxt;
} edge[SIZE << 1];
void Add_Edge (int u, int v, int c, int d) {
  ++ecnt;
  edge[ecnt].v = v;
  edge[ecnt].c = c;
  edge[ecnt].d = d;
  edge[ecnt].nxt = first[u];
  first[u] = ecnt;
}

struct Query {
  int x, y, k;
  int id;
};
vector<Query> V[SIZE];

int dep[SIZE], dp[SIZE][17];

void dfs (int u) {
  EREP (i, u) {
    Edge& e = edge[i];
    if (e.v == dp[u][0]) continue;
    dep[e.v] = dep[u] + 1;
    dp[e.v][0] = u;
    dfs (e.v);
  }
}

int ans[SIZE], cnt[SIZE], sum[SIZE];

void Up (int& u, int step) {
  REP (i, 0, 16) if (1 << i & step)
    u = dp[u][i];
}

int LCA (int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  Up (u, dep[u] - dep[v]);
  if (u == v) return u;
  DREP (i, 16, 0) if (dp[u][i] != dp[v][i])
    u = dp[u][i], v = dp[v][i];
  return dp[u][0];
}
int dis;

void DFS (int u) {
  FOR (i, 0, V[u].size()) {
    Query& q = V[u][i];
    ans[q.id] += (dis - sum[q.x] + cnt[q.x] * y) * q.k;
  }
  EREP (i, u) {
    Edge& e = edge[i];
    if (e.v == dp[u][0]) continue;
    dis += e.d;
    sum[e.c] += e.d;
    ++cnt[e.v];
    DFS (e.v);
    dis -= e.d;
    sum[e.c] -= e.d;
    --cnt[e.v];
  }
}

int main () {
  scanf ("%d%d", &n, &q);

  FOR (i, 1, n) {
    int u, v, c, d;
    scanf ("%d%d%d%d", &u, &v, &c, &d);
    Add_Edge (u, v, c, d);
    Add_Edge (v, u, c, d);
  }

  dfs (1);
  REP(i, 1, 16) REP (j, 1, n)
    dp[j][i] = dp[dp[j][i - 1]][i - 1];

  REP (i, 1, q) {
    int x, y, u, v;
    scanf ("%d%d%d%d", &x, &y, &u, &v);
    int lca = LCA (u, v);
    V[u].push_back((Query) <% x, y, 1, i%>);
    V[v].push_back((Query) <% x, y, 1, i%>);
    V[lca].push_back((Query) <% x, y, -2, i%>);
  }

  REP (i, 1, q) printf ("%d\n", ans[i]);
  return 0;
}


Compiler output:
a.cc: In function 'void DFS(int)':
a.cc:66:47: error: 'y' was not declared in this scope
   66 |     ans[q.id] += (dis - sum[q.x] + cnt[q.x] * y) * q.k;
      |                                               ^
Language: C

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>
#include<cassert>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX  210000


typedef long long ll;
typedef pair<ll,ll> P;

struct edge{ll to, cost, col;};

vector<edge> G[MAX];
ll d[MAX], V;

int dijkstra(int x, int y, ll s, int g){
	priority_queue<P,vector<P>,greater<P>> q;
	fill(d,d+V, INF);
	
	d[s] = 0;
	q.push(P(0,s));
	assert(s < MAX);
	while(!q.empty()){ 
		P p = q.top();q.pop();
		ll v = p.second;assert(v< MAX);
		// cout<<"v = "<<v<<" g = "<<g<<endl;
		if(v == g) return d[g];assert(g < MAX);
		
		if(d[v] < p.first) continue;
		
		for(edge e : G[v]){
			int cost = e.cost;
			// cout<<e.to<<endl;
			if(e.col == x) cost = y;
			
			// cout<<"cost "<<cost<<endl;
			assert(e.to < MAX);
			if(d[e.to] > d[v] + cost){
				d[e.to] = d[v] + cost;
				q.push(P(d[e.to],e.to));
			}
		}
	}
	assert(g < MAX);
	return d[g];
}
signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	int N, Q;
	int a, b, c, d;
	int y, x, u, v;
	
	V = N+10;
	
	cin>>N>>Q;
	
	for(int i = 0; i < N-1; i++){
		cin>>a>>b>>c>>d;
		edge e;
		e.to = b;
		e.col = c;
		e.cost = d;
		assert(a < MAX);
		G[a].push_back(e);
		
		e.to = a;
		assert(b < MAX);
		G[b].push_back(e);
	}
	
	for(int i = 0; i < Q; i++){
		cin>>x>>y>>u>>v;
		
		cout<<dijkstra(x,y,u,v)<<endl;
	}
	
	return 0;
}

Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX  110000


typedef long long ll;
typedef pair<ll,ll> P;

struct edge{ll to, cost, col;};

vector<edge> G[MAX];
ll d[MAX], V;

int dijkstra(int x, int y, ll s, int g){
	priority_queue<P,vector<P>,greater<P>> q;
	fill(d,d+V, INF);
	
	d[s] = 0;
	q.push(P(0,s));
	
	while(!q.empty()){ 
		P p = q.top();q.pop();
		ll v = p.second;
		// cout<<"v = "<<v<<" g = "<<g<<endl;
		if(v == g) return d[g];
		
		if(d[v] < p.first) continue;
		
		for(edge e : G[v]){
			int cost = e.cost;
			// cout<<e.to<<endl;
			if(e.col == x) cost = y;
			
			// cout<<"cost "<<cost<<endl;
			
			if(d[e.to] > d[v] + cost){
				d[e.to] = d[v] + cost;
				q.push(P(d[e.to],e.to));
			}
		}
	}

	return d[g];
}
signed main(){
	// cin.tie(0);
	// ios::sync_with_stdio(false);
	// cout<<fixed<<setprecision(10);
	
	int N, Q;
	int a, b, c, d;
	int y, x, u, v;
	V = N+10;
	
	cin>>N>>Q;
	
	for(int i = 0; i < N-1; i++){
		cin>>a>>b>>c>>d;
		edge e;
		e.to = b;
		e.col = c;
		e.cost = d;
		
		G[a].push_back(e);
		
		e.to = a;
		G[b].push_back(e);
	}
	
	for(int i = 0; i < Q; i++){
		cin>>x>>y>>u>>v;
		
		cout<<dijkstra(x,y,u,v)<<endl;
	}
	
	return 0;
}

Compiler output:
main.c:1:9: fatal error: iostream: No such file or directory
    1 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
#define int long long
#define mid (l+r)/2
int n,m,cnt,t,top,ru[N],chu[N],a[N],b[N],dis[N],head[N];
int tree[N<<7],L[N<<7],R[N<<7],sum[N<<7],gs[N<<7],f[N][20];
struct node{
	int too,next,col,zh;
}edge[N*2];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
void add(int a,int b,int c,int d)
{
	edge[++top].too=b;edge[top].col=c;edge[top].zh=d;
	edge[top].next=head[a];head[a]=top;
}
bool pd(int x,int y)
{
	if(ru[x]<=ru[y]&&chu[x]>=chu[y])return true;
	return false;
}
int LCA(int x,int y)
{
	if(pd(x,y))return x;
	if(pd(y,x))return y;
	int k=x;
	for(int i=17;i>=0;i--)
		if((f[k][i]>0)&&(!pd(f[k][i],y)))k=f[k][i];
	return f[k][0];
}
int update(int pre,int l,int r,int x,int val)
{
    int rt=++cnt;
    L[rt]=L[pre];R[rt]=R[pre];sum[rt]=sum[pre];gs[rt]=gs[pre];
    if(l==r)
	{
		gs[rt]=gs[pre]+1;sum[rt]=sum[pre]+val;
		return rt;
	}
    if(x<=mid)L[rt]=update(L[pre],l,mid,x,val);
    else R[rt]=update(R[pre],mid+1,r,x,val);
    return rt;
}
int query1(int x,int y,int xx,int yy,int l,int r,int col)
{
	if(l==r)
	{
//		cout<<sum[x]+sum[y]-sum[xx]-sum[yy]<<endl;
		return sum[x]+sum[y]-sum[xx]-sum[yy];
	}
	if(col<=mid)return query1(L[x],L[y],L[xx],L[yy],l,mid,col);
	else return query1(R[x],R[y],R[xx],R[yy],mid+1,r,col);
}
int query2(int x,int y,int xx,int yy,int l,int r,int col)
{
	if(l==r)
	{
//		cout<<gs[x]+gs[y]-gs[xx]-gs[yy]<<endl;
		return gs[x]+gs[y]-gs[xx]-gs[yy];
	}
	if(col<=mid)return query2(L[x],L[y],L[xx],L[yy],l,mid,col);
	else return query2(R[x],R[y],R[xx],R[yy],mid+1,r,col);
}
void dfs(int u,int fa,int dep,int col,int zh)
{
	dis[u]=dep;
	tree[u]=update(tree[fa],1,100001,col,zh);
	ru[u]=++t;f[u][0]=fa;
	for(int i=head[u];i;i=edge[i].next)
	{
		int v=edge[i].too;
		if(v==fa)continue;
		dfs(v,u,dep+edge[i].zh,edge[i].col,edge[i].zh);
	}
	chu[u]=++t;
}
int main()
{
	n=read();m=read();	
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read(),z=read(),zz=read();
		add(x,y,z,zz);
		add(y,x,z,zz);
	}
	dfs(1,0,0,100001,0);
	for(int i=1;i<=17;i++)
        for(int j=1;j<=n;j++)
            f[j][i]=f[f[j][i-1]][i-1];
	while(m--)
	{
		int col=read(),k=read(),x=read(),y=read();
		if(ru[x]>ru[y])swap(x,y);
		int lca=LCA(x,y);
		int ans=dis[x]+dis[y]-2*dis[lca];
		int xu=query1(tree[x],tree[y],tree[lca],tree[f[lca][0]],1,100001,col);
		ans=ans-xu;
		int gs=query2(tree[x],tree[y],tree[lca],tree[f[lca][0]],1,100001,col);
		ans=ans+gs*k;
		cout<<ans<<endl;
	}
	return 0;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

 r4f747ui 74ri4r7ifci7fr4
         764686437hgsdkmhj
   56e465477687890228yugh
   bbbb
   uty63 78I32YTWQE2T6
    7IUT365214I964UEHYDLIOQA
   7TTTYTYTEYT
   HGHGJ
   GGHG
   GHWGJFS
   HJFDSGH
   JDHGFSHJSF
   GFSJHGJSKJ
   HFJDSGGGGGGGGGGGG
   666666666666
   56453258219710
    I73RBGT38UR3 86YR38E

Compiler output:
a.cc:1:2: error: 'r4f747ui' does not name a type
    1 |  r4f747ui 74ri4r7ifci7fr4
      |  ^~~~~~~~
Language: C++

#include<iostream>
#include<string>
using namespace std;

int main() {
	string s; cin >> s;
	sort(s.begin(), s.end());
	if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:9: error: 'sort' was not declared in this scope; did you mean 'short'?
    7 |         sort(s.begin(), s.end());
      |         ^~~~
      |         short
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>

using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から


typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

ll gcd(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    //a>=b
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

#define MOD ((ll)1e+9 + 7)



//cout<<fixed<<setprecision(10);
int main(){
    string s;
    cin>>s;
    int c=0;
    sort(s.begin(),s.end());
    if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3]){
        cout<<"Yes"<,endl;
    }
    else{
        cout<<"No"<<endl;
    }



    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:76:21: error: expected primary-expression before ',' token
   76 |         cout<<"Yes"<,endl;
      |                     ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  
  string S;
  cin >> S;
  
  if (S.at(0) == S.at(1) && S.at(2) == S.at(3) $$ S.at(0) != S.at(2)) {
    cout << "Yes" << endl;
  }
  else if (S.at(0) == S.at(2) && S.at(1) == S.at(3) $$ S.at(0) != S.at(1)) {
    cout << "Yes" << endl;
  }
  else if (S.at(0) == S.at(3) && S.at(2) == S.at(1) $$ S.at(0) != S.at(1)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  

return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:47: error: expected ')' before '$$'
    9 |   if (S.at(0) == S.at(1) && S.at(2) == S.at(3) $$ S.at(0) != S.at(2)) {
      |      ~                                        ^~~
      |                                               )
a.cc:12:52: error: expected ')' before '$$'
   12 |   else if (S.at(0) == S.at(2) && S.at(1) == S.at(3) $$ S.at(0) != S.at(1)) {
      |           ~                                        ^~~
      |                                                    )
a.cc:15:52: error: expected ')' before '$$'
   15 |   else if (S.at(0) == S.at(3) && S.at(2) == S.at(1) $$ S.at(0) != S.at(1)) {
      |           ~                                        ^~~
      |                                                    )
Language: C++

#include <bits/stdc++.h>
using namespace std;

string s;

int main(){
  string res = "No";
  if(s[0] == s[1]){
    if(s[2] == s[3]){
      if(s[0] != s[2]){
        res = "Yes";
      }
    }
  }else if(s[0] == s[2]){
    if(s[1] == s[3]){
      if(s[0] != s[1]){
        res = "Yes";
      }
    }
  }else if(s[0] == s[3]){
    if(s[1] == s[2]){
      if s[0] != s[1]){
        res = "Yes";
      }
    }
  }
  cout << res << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:10: error: expected '(' before 's'
   22 |       if s[0] != s[1]){
      |          ^
      |          (
Language: C++

#include<bits/stdc++.h>
using namespace std;

int main(){
  string s;
  cin >> s;
  int cnt = 1;
  for (int i = 1; i <4; i++){
    cnt++;
    if(s[0] == s[i]) break;
  }
  if(cnt == 2){
    if(s[2] == s[3] && s[0] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }else if (cnt == 3){
    if(s[1] == s[3] && s[0] != s[1]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }else if (cnt == 4){
    if(s[1] == s[2] && s[0] != s[1) cout << "Yes" << endl;
    else cout << "No" << endl;
  }else cout << "No" << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:35: error: expected ']' before ')' token
   19 |     if(s[1] == s[2] && s[0] != s[1) cout << "Yes" << endl;
      |                                   ^
      |                                   ]
Language: C++

#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
  cin>>s;
  if(s.at(0)==s.at(1)&&s.at(2)==s.at(3)&&s.at(0)!=s.at(2)){
    cout<<"Yes"<<endl;  
  }
  else  if(s.at(0)!=s.at(1)&&s.at(0)==s.at(2)&&s.at(1)==s.at(3)){
    cout<<"Yes"<<endl;  
  }
   else  if(s.at(0)==s.at(3)&&s.at(2)==s.at(3)s.at(0)!=s.at(2)){
    cout<<"Yes"<<endl;  
  }
  else{cout<<"No"<<endl;}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:12:47: error: expected ')' before 's'
   12 |    else  if(s.at(0)==s.at(3)&&s.at(2)==s.at(3)s.at(0)!=s.at(2)){
      |            ~                                  ^
      |                                               )
Language: C

#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
	
	string s;
	int cnt = 0;
	cin >> s;
	sort(s.begin(), s.end());
	for (int i = 0; i < s.length()-1; i++)
		if (s[i] == s[i + 1])
			cnt++;
	if (cnt == 2)
		cout << "Yes";
	else
		cout << "No";
}


Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <algorithm>
using namespace std;


int main ()
{

string s;
cin >> s;

sort(s.begin(), s.end());

if(s[0]==s[1] &&  && s[1]!=s[2] && s[2]==s[3])
{
	 cout << "Yes" << endl;
}
else
{
	cout << "No" << endl;
}

	return 0;
}











Compiler output:
a.cc: In function 'int main()':
a.cc:14:23: error: expected ')' before '[' token
   14 | if(s[0]==s[1] &&  && s[1]!=s[2] && s[2]==s[3])
      |   ~                   ^
      |                       )
a.cc:14:22: error: label 's' used but not defined
   14 | if(s[0]==s[1] &&  && s[1]!=s[2] && s[2]==s[3])
      |                      ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
  pr(b);
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if (s[0] == s[1] && s[2] == s[3])
    Yes();
  else
    No();
  　
}


Compiler output:
a.cc:66:3: error: extended character 　 is not valid in an identifier
   66 |   　
      |   ^
a.cc: In function 'int main()':
a.cc:66:3: error: '\U00003000' was not declared in this scope
   66 |   　
      |   ^~
Language: C++

#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main(){
	string a;
	cin>>a;
	if(a[0]==a[1]&& a[2]==a[3]&& a[0]!=a[2]){
		cout<<"Yes";
	}
	if(a[0]==a[2]&& a[1]==a[3]&& a[0]!=a[3]){
		cout<<"Yes";
	}
	if(a[0]==a[3]&& a[2]==a[1] && a[0]!=a[2]){
		cout<<"Yes";
	}
	else {
		cout<<"No";
	}


Compiler output:
a.cc: In function 'int main()':
a.cc:19:10: error: expected '}' at end of input
   19 |         }
      |          ^
a.cc:5:11: note: to match this '{'
    5 | int main(){
      |           ^
Language: C++

#include <bits/stdc++.h>
using namespace std;

int main() {
  char a, b, c, d;
  cin >> a >> b >> c >> d;
  if((a == b && c == d && a != c) || (a == c && b == d && a != b) ||
     (a == d && b == c && a != b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:34: error: expected ';' before 'cout'
    8 |      (a == d && b == c && a != b) cout << "Yes" << endl;
      |                                  ^~~~~
      |                                  ;
a.cc:9:3: error: expected primary-expression before 'else'
    9 |   else cout << "No" << endl;
      |   ^~~~
a.cc:8:57: error: expected ')' before 'else'
    8 |      (a == d && b == c && a != b) cout << "Yes" << endl;
      |                                                         ^
      |                                                         )
    9 |   else cout << "No" << endl;
      |   ~~~~                                                   
a.cc:7:5: note: to match this '('
    7 |   if((a == b && c == d && a != c) || (a == c && b == d && a != b) ||
      |     ^
Language: C++

    #include<bits/stdc++.h>
    using namespace std;
     
    int main(){
    	string s;
      	cin>>s;
      	map<char,int> mp;
      	for(int i=0;i<s.length();i++){
          mp[s[i]]++;
        }
      	bool flag = true;;
      	for(auto x:mp){
          if(x.second!=f){
            flag = false;
          }
        }
      	if(flag)
          cout<<"YES"<<endl;
      	else
          cout<<"NO"<<endl;
      
      	return 0;
    }

Compiler output:
a.cc: In function 'int main()':
a.cc:13:24: error: 'f' was not declared in this scope
   13 |           if(x.second!=f){
      |                        ^