Language: C++

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
using namespace std;

const int MAXN = 100100;
struct Edge
{
	int to,next;
}edge[MAXN*2];
int head[MAXN],tot;
int top[MAXN];//top[v]陦ィ遉コv謇?惠逧??體セ逧?。カ遶ッ闃らせ
int fa[MAXN]; //辷カ莠イ闃らせ
int deep[MAXN];//豺ア蠎ヲ
int num[MAXN];//num[v]陦ィ遉コ莉・v荳コ譬ケ逧?ュ先?逧?鰍轤ケ謨ー
int p[MAXN];//p[v]陦ィ遉コv荳主?辷カ莠イ闃らせ逧?ソ櫁セケ蝨ィ郤ソ谿オ譬台クュ逧?ス咲スョ
int fp[MAXN];//蜥継謨ー扈?嶌蜿?int son[MAXN];//驥榊?蟄?int pos;

void init()
{
	tot = 0;
	memset(head,-1,sizeof(head));
	pos = 0;
	memset(son,-1,sizeof(son));
}

inline void addedge(int u,int v)
{
	edge[tot].to = v;edge[tot].next = head[u];head[u] = tot++;
}

void dfs1(int u,int pre,int d) //隨ャ荳?″dfs豎ょ?fa,deep,num,son
{
	deep[u] = d;
	fa[u] = pre;
	num[u] = 1;
	for(int i = head[u];i != -1; i = edge[i].next)
	{
		int v = edge[i].to;
		if(v != pre)
		{
			dfs1(v,u,d+1);
			num[u] += num[v];
			if(son[u] == -1 || num[v] > num[son[u]])
				son[u] = v;
		}
	}
}

inline void getpos(int u,int sp) //隨ャ莠碁″dfs豎ょ?top蜥継
{
	top[u] = sp;
	if(son[u] != -1)
	{
		p[u] = pos++;
		fp[p[u]] = u;
		getpos(son[u],sp);
	}
	else
	{
		p[u] = pos++;
		fp[p[u]] = u;
		return;
	}
	for(int i = head[u] ; i != -1; i = edge[i].next)
	{
		int v = edge[i].to;
		if(v != son[u] && v != fa[u])
			getpos(v,v);
	}
}

//郤ソ谿オ譬?struct Node
{
	int l,r;
	long long sum;
	long long lazy;
}segTree1[MAXN<<2],segTree2[MAXN<<2];
inline void build(Node segTree[],int i,int l,int r)
{
	segTree[i].l = l;
	segTree[i].r = r;
	segTree[i].sum = 0;
	segTree[i].lazy =0;
	if(l == r)return;
	int mid =((l+r)>>1);
	build(segTree,i<<1,l,mid);
	build(segTree,(i<<1)|1,mid+1,r);
}

inline void push_up(Node segTree[],int i)
{
	segTree[i].sum= segTree[i<<1].sum+segTree[i<<1|1].sum;
}

inline void push_down(Node segTree[],int i){
	if(segTree[i].lazy){
		segTree[i<<1].lazy+=segTree[i].lazy;
		segTree[i<<1|1].lazy+=segTree[i].lazy;
		segTree[i<<1].sum+=(segTree[i<<1].r-segTree[i<<1].l+1)*segTree[i].lazy;
		segTree[i<<1|1].sum+=(segTree[i<<1|1].r-segTree[i<<1|1].l+1)*segTree[i].lazy;
		segTree[i].lazy=0;
	}
}

inline void update(Node segTree[],int i,int l,int r,int val)//譖エ譁ー蛹コ髣エ 
{
	if(segTree[i].l == l && segTree[i].r == r)
	{
		segTree[i].lazy+= val;
		segTree[i].sum+=(segTree[i].r-segTree[i].l+1)*val;
		return;
	}
	push_down(segTree,i);
	int mid = (segTree[i].l + segTree[i].r)>>1;
	if(r <= mid){
		update(segTree,i<<1,l,r,val);
	}
	else if(l>mid){
		update(segTree,(i<<1)|1,l,r,val);
	}
	else{
		update(segTree,i<<1,l,mid,val);
		update(segTree,i<<1|1,mid+1,r,val);
	} 
	push_up(segTree,i);
}

inline int query(Node segTree[],int i,int l,int r)//譟・隸「 
{
	if(segTree[i].l == l && segTree[i].r == r)
		return segTree[i].sum;
	push_down(segTree,i);
	int mid = (segTree[i].l + segTree[i].r)>>1;
	if(r <= mid){
		return query(segTree,i<<1,l,r);
	}
	else if(l>mid){
		return query(segTree,i<<1|1,l,r);
	}
	else {
		return query(segTree,i<<1,l,mid);
		return query(segTree,i<<1|1,mid+1,r);
	}
}

inline void add2(Node segTree[],int u,int v,int val)//譟・隸「u->v霎ケ逧?怙螟ァ蛟シ
{
	int f1 = top[u], f2 = top[v];
	int tmp = 0;
	while(f1 != f2)
	{
		if(deep[f1] < deep[f2])
		{
			swap(f1,f2);
			swap(u,v);
		}
		update(segTree,1,p[f1],p[u],val);
		u = fa[f1]; f1 = top[u];
	}
	if(u == v){
		return ;
	}
	if(deep[u] > deep[v]) swap(u,v);
	update(segTree,1,p[son[u]],p[v],val);
}

int find(Node segTree[],int u,int v)//譟・隸「u->v霎ケ逧?怙螟ァ蛟シ
{
	int f1 = top[u], f2 = top[v];
	int tmp = 0;
	while(f1 != f2)
	{
		if(deep[f1] < deep[f2])
		{
			swap(f1,f2);
			swap(u,v);
		}
		tmp = max(tmp,query(segTree,1,p[f1],p[u]));
		u = fa[f1]; f1 = top[u];
	}
	if(u == v)return tmp;
	if(deep[u] > deep[v]) swap(u,v);
	return max(tmp,query(segTree,1,p[son[u]],p[v]));
}

int e[MAXN][2];	
struct Re{
	char s[10];
	int u,v,k;
};
Re re[MAXN];

struct Re2{
	int l,r,k;
};
Re2 re2[MAXN];

int ans[2][MAXN];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int T;
	int n,q;
	scanf("%d",&T);
	
	int _=0;
	int i;
	int u,v,pu,pv;
	while(T--)
	{
		init();
		scanf("%d%d",&n,&q);
		for(i = 0;i < n-1;i++)
		{
			scanf("%d%d",&e[i][0],&e[i][1]);
			addedge(e[i][0],e[i][1]);
			addedge(e[i][1],e[i][0]);
		}
		
		addedge(n+1,1);
		addedge(1,n+1); 
		
		dfs1(n+1,0,0);
		getpos(n+1,n+1);
		
		build(segTree1,1,0,pos-1);
		build(segTree2,1,0,pos-1);
		
		for(i=0;i<q;i++){
			scanf("%s%d%d%d",re[i].s,&re[i].u,&re[i].v,&re[i].k);
			if(re[i].s[3]=='2')add2(segTree2,re[i].u,re[i].v,re[i].k);
			else add2(segTree1,fa[re[i].u],re[i].v,re[i].k);
		}
		//邂礼噪譏ッ霎ケ
		for(i=0;i<n-1;i++){
			u=e[i][0],v=e[i][1];
			pu=p[u];
			pv=p[v];
			if(pu==v)ans[0][i]=query(segTree2,1,pu,pu);
			else ans[0][i]=query(segTree2,1,pv,pv);
		}
		//邂礼噪譏ッ轤ケ 
		for(i=1;i<=n;i++)ans[1][i]=query(segTree1,1,p[i],p[i]);
		
		printf("Case #%d:\n",++_);
		for(i=1;i<=n;i++){
			if(i!=1)printf(" ");
			printf("%d",ans[1][i]);
		}
		puts("");
		for(i=0;i<n-1;i++){
			if(i)printf(" ");
			printf("%d",ans[0][i]);
		}
		puts("");
	}
    return 0;
}

Compiler output:
a.cc: In function 'void init()':
a.cc:31:9: error: 'pos' was not declared in this scope; did you mean 'pow'?
   31 |         pos = 0;
      |         ^~~
      |         pow
a.cc:32:16: error: 'son' was not declared in this scope; did you mean 'sin'?
   32 |         memset(son,-1,sizeof(son));
      |                ^~~
      |                sin
a.cc: In function 'void dfs1(int, int, int)':
a.cc:52:28: error: 'son' was not declared in this scope; did you mean 'sin'?
   52 |                         if(son[u] == -1 || num[v] > num[son[u]])
      |                            ^~~
      |                            sin
a.cc: In function 'void getpos(int, int)':
a.cc:61:12: error: 'son' was not declared in this scope; did you mean 'sin'?
   61 |         if(son[u] != -1)
      |            ^~~
      |            sin
a.cc:63:24: error: 'pos' was not declared in this scope; did you mean 'pow'?
   63 |                 p[u] = pos++;
      |                        ^~~
      |                        pow
a.cc:69:24: error: 'pos' was not declared in this scope; did you mean 'pow'?
   69 |                 p[u] = pos++;
      |                        ^~~
      |                        pow
a.cc:76:25: error: 'son' was not declared in this scope; did you mean 'sin'?
   76 |                 if(v != son[u] && v != fa[u])
      |                         ^~~
      |                         sin
a.cc: At global scope:
a.cc:82:1: error: expected unqualified-id before '{' token
   82 | {
      | ^
a.cc:86:2: error: 'segTree1' does not name a type
   86 | }segTree1[MAXN<<2],segTree2[MAXN<<2];
      |  ^~~~~~~~
a.cc:87:13: error: variable or field 'build' declared void
   87 | inline void build(Node segTree[],int i,int l,int r)
      |             ^~~~~
a.cc:87:19: error: 'Node' was not declared in this scope
   87 | inline void build(Node segTree[],int i,int l,int r)
      |                   ^~~~
a.cc:87:34: error: expected primary-expression before 'int'
   87 | inline void build(Node segTree[],int i,int l,int r)
      |                                  ^~~
a.cc:87:40: error: expected primary-expression before 'int'
   87 | inline void build(Node segTree[],int i,int l,int r)
      |                                        ^~~
a.cc:87:46: error: expected primary-expression before 'int'
   87 | inline void build(Node segTree[],int i,int l,int r)
      |                                              ^~~
a.cc:99:13: error: variable or field 'push_up' declared void
   99 | inline void push_up(Node segTree[],int i)
      |             ^~~~~~~
a.cc:99:21: error: 'Node' was not declared in this scope
   99 | inline void push_up(Node segTree[],int i)
      |                     ^~~~
a.cc:99:36: error: expected primary-expression before 'int'
   99 | inline void push_up(Node segTree[],int i)
      |                                    ^~~
a.cc:104:13: error: variable or field 'push_down' declared void
  104 | inline void push_down(Node segTree[],int i){
      |             ^~~~~~~~~
a.cc:104:23: error: 'Node' was not declared in this scope
  104 | inline void push_down(Node segTree[],int i){
      |                       ^~~~
a.cc:104:38: error: expected primary-expression before 'int'
  104 | inline void push_down(Node segTree[],int i){
      |                                      ^~~
a.cc:114:13: error: variable or field 'update' declared void
  114 | inline void update(Node segTree[],int i,int l,int r,int val)//譖エ譁ー蛹コ髣エ
      |             ^~~~~~
a.cc:114:20: error: 'Node' was not declared in this scope
  114 | inline void update(Node segTree[],int i,int l,int r,int val)//譖エ譁ー蛹コ髣エ
      |                    ^~~~
a.cc:114:35: error: expected primary-expression before 'int'
  114 | inline void update(Node segTree[],int i,int l,int r,int val)//譖エ譁ー蛹コ髣エ
      |                                   ^~~
a.cc:114:41: error: expected primary-expression before 'int'
  114 | inline void update(Node segTree[],int i,int l,int r,int val)//譖エ譁ー蛹コ髣エ
      |                                         ^~~
a.cc:114:47: error: expected primary-expression before 'int'
  114 | inline void update(Node segTree[],int i,int l,int r,int val)//譖エ譁ー蛹コ髣エ
      |                                               ^~~
a.cc:114:53: error: expected primary-expression before 'int'
  114 | inline void update(Node segTree[],int i,int l,int r,int val)//譖エ譁ー蛹コ髣エ
      |                                                     ^~~
a.cc:137:18: error: 'Node' was not declared in this scope
  137 | inline int query(Node segTree[],int i,int l,int r)//譟・隸「
      |                  ^~~~
a.cc:137:33: error: expected primary-expression before 'int'
  137 | inline int query(Node segTree[],int i,int l,int r)//譟・隸「
      |                                 ^~~
a.cc:137:39: error: expected primary-expression before 'int'
  137 | inline int query(Node segTree[],int i,int l,int r)//譟・隸「
      |                                       ^~~
a.cc:137:45: error: expected primary-expression before 'int'
  137 | inline int query(Node segTree[],int i,int l,int r)//譟・隸「
      |                                             ^~~
a.cc:137:50: error: expression list treated as compound expression in initializer [-fpermissive]
  137 | inline int query(Node segTree[],int i,int l,int r)//譟・隸「
      |                                                  ^
a.cc:155:13: error: variable or field 'add2' declared void
  155 | inline void add2(Node segTree[],int u,int v,int val)//譟・隸「u->v霎ケ逧?怙螟ァ蛟シ
      |             ^~~~
a.cc:155:18: error: 'Node' was not declared in this scope
  155 | inline void add2(Node segTree[],int u,int v,int val)//譟・隸「u->v霎ケ逧?怙螟ァ蛟シ
      |                  ^~~~
a.cc:155:33: error: expected primary-expression before 'int'
  155 | inline void add2(Node segTree[],int u,int v,int val)//譟・隸「u->v霎ケ逧?怙螟ァ蛟シ
      |                                 ^~~
a.cc:155:39: error: expected primary-expression before 'int'
  155 | inline void add2(Node segTree[],int u,int v,int val)//譟・隸「u->v霎ケ逧?怙螟ァ蛟シ
      |                                       ^~~
a.cc:155:45: error: expected primary-expression before 'int'
  155 | inline void add2(Node segTree[],int u,int v,int val)//譟・隸「u->v霎ケ逧?怙螟ァ蛟シ
      |                                             ^~~
a.cc:176:10: error: 'Node' was not declared in this scope
  176 | int find(Node segTree[],int u,int v)//譟・隸「u->v霎ケ逧?怙螟ァ蛟シ
      |          ^~~~
a.cc:176:25: error: expected primary-expression before 'int'
  176 | int find(Node segTree[],int u,int v)//譟・隸「u->v霎ケ逧?怙螟ァ蛟シ
      |                         ^~~
a.cc:176:31: error: expected primary-expression before 'int'
  176 | int find(Node segTree[],int u,int v)//譟・隸「u->v霎ケ逧?怙螟ァ蛟シ
      |                               ^~~
a.cc:176:36: error: expression list treated as compound expression in initializer [-fpermissive]
  176 | int find(Node segTree[],int u,int v)//譟・隸「u->v霎ケ逧?怙螟ァ蛟シ
      |                                    ^
a.cc: In function 'int main()':
a.cc:236:23: error: 'segTree1' was not declared in this scope
  236 |                 build(segTree1,1,0,pos-1);
      |                       ^~~~~~~~
a.cc:236:36: error: 'pos' was not declared in this scope; did you mean 'pow'?
  236 |                 build(segTree1,1,0,pos-1);
      |                                    ^~~
      |                                    pow
a.cc:236:17: error: 'build' was not declared in this scope
  236 |                 build(segTree1,1,0,pos-1);
      |                 ^~~~~
a.cc:237:23: error: 'segTree2' was not declared in this scope
  237 |                 build(segTree2,1,0,pos-1);
      |                       ^~~~~~~~
a.cc:241:44: error: 'add2' was not declared in this scope
  241 |                         if(re[i].s[3]=='2')add2(segTree2,re[i].u,re[i].v,re[i].k);
      |                                            ^~~~
a.cc:242:30: error: 'add2' was not declared in this scope
  242 |                         else add2(segTree1,fa[re[i].u],re[i].v,re[i].k);
      |                              ^~~~
a.cc:249:49: error: 'query' cannot be used as a function
  249 |                         if(pu==v)ans[0][i]=query(segTree2,1,pu,pu);
      |                                            ~~~~~^~~~~~~~~~~~~~~~~~
a.cc:250:45: error: 'query' cannot be used as a function
  250 |                         else ans[0][i]=query(segTree2,1,pv,pv);
      |                                        ~~~~~^~~~~~~~~~~~~~~~~~
a.cc:253:49: error: 'query' cannot be used as a function
  253 |                 for(i=1;i<=n;i++)ans[1][i]=query(segTree1,1,p[i],p[i]);
      |                                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~