Language: C++

#include <bits/stdc++.h>
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
typedef long long ll;
int main() {
	queue<P> Q;
	ll int n,q;
	cin>>n>>q;
	ll int cn[n-1][2];
	for(ll int i=0;i<n-1;i++){
		cin>>cn[i][0]>>cn[i][1];
		if(cn[i][0]==1){
			Q.push(P(cn[i][0],cn[i][1]));
		}
	}
	ll int p[q][2];
	ll int ans[n+1]={0};
	for(ll int i=0;i<n;i++)ans[i]=0;
	for(ll int i=0;i<q;i++){
		cin>>p[i][0]>>p[i][1];
	}
	while(Q.size()){
		P a=Q.front();
		Q.pop();
		for(ll int i=0;i<q;i++){
		if(p[i][0]==a.first){
			ans[a.first]+=p[i][1];
			p[i][1]=0;
		}
		if(p[i][0]==a.second){
			ans[a.second]+=p[i][1];
			p[i][1]=0;
		}
	}
		ans[a.second]+=ans[a.first];
		for(ll int i=0;i<n-1;i++){
		if(cn[i][0]==a.second){
			Q.push(P(cn[i][0],cn[i][1]));
		}
	}
	}
	for(ll int i=1;i<=n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:8:9: error: two or more data types in declaration of 'n'
    8 |         ll int n,q;
      |         ^~
a.cc:8:9: error: two or more data types in declaration of 'q'
a.cc:9:14: error: 'n' was not declared in this scope
    9 |         cin>>n>>q;
      |              ^
a.cc:9:17: error: 'q' was not declared in this scope
    9 |         cin>>n>>q;
      |                 ^
a.cc:10:9: error: two or more data types in declaration of 'cn'
   10 |         ll int cn[n-1][2];
      |         ^~
a.cc:11:13: error: two or more data types in declaration of 'i'
   11 |         for(ll int i=0;i<n-1;i++){
      |             ^~
a.cc:11:24: error: 'i' was not declared in this scope
   11 |         for(ll int i=0;i<n-1;i++){
      |                        ^
a.cc:12:22: error: 'cn' was not declared in this scope; did you mean 'yn'?
   12 |                 cin>>cn[i][0]>>cn[i][1];
      |                      ^~
      |                      yn
a.cc:17:9: error: two or more data types in declaration of 'p'
   17 |         ll int p[q][2];
      |         ^~
a.cc:18:9: error: two or more data types in declaration of 'ans'
   18 |         ll int ans[n+1]={0};
      |         ^~
a.cc:19:13: error: two or more data types in declaration of 'i'
   19 |         for(ll int i=0;i<n;i++)ans[i]=0;
      |             ^~
a.cc:19:24: error: 'i' was not declared in this scope
   19 |         for(ll int i=0;i<n;i++)ans[i]=0;
      |                        ^
a.cc:19:32: error: 'ans' was not declared in this scope; did you mean 'abs'?
   19 |         for(ll int i=0;i<n;i++)ans[i]=0;
      |                                ^~~
      |                                abs
a.cc:20:13: error: two or more data types in declaration of 'i'
   20 |         for(ll int i=0;i<q;i++){
      |             ^~
a.cc:20:24: error: 'i' was not declared in this scope
   20 |         for(ll int i=0;i<q;i++){
      |                        ^
a.cc:21:22: error: 'p' was not declared in this scope
   21 |                 cin>>p[i][0]>>p[i][1];
      |                      ^
a.cc:26:21: error: two or more data types in declaration of 'i'
   26 |                 for(ll int i=0;i<q;i++){
      |                     ^~
a.cc:26:32: error: 'i' was not declared in this scope
   26 |                 for(ll int i=0;i<q;i++){
      |                                ^
a.cc:27:20: error: 'p' was not declared in this scope
   27 |                 if(p[i][0]==a.first){
      |                    ^
a.cc:28:25: error: 'ans' was not declared in this scope; did you mean 'abs'?
   28 |                         ans[a.first]+=p[i][1];
      |                         ^~~
      |                         abs
a.cc:31:20: error: 'p' was not declared in this scope
   31 |                 if(p[i][0]==a.second){
      |                    ^
a.cc:32:25: error: 'ans' was not declared in this scope; did you mean 'abs'?
   32 |                         ans[a.second]+=p[i][1];
      |                         ^~~
      |                         abs
a.cc:36:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   36 |                 ans[a.second]+=ans[a.first];
      |                 ^~~
      |                 abs
a.cc:37:21: error: two or more data types in declaration of 'i'
   37 |                 for(ll int i=0;i<n-1;i++){
      |                     ^~
a.cc:37:32: error: 'i' was not declared in this scope
   37 |                 for(ll int i=0;i<n-1;i++){
      |                                ^
a.cc:38:20: error: 'cn' was not declared in this scope; did you mean 'yn'?
   38 |                 if(cn[i][0]==a.second){
      |                    ^~
      |                    yn
a.cc:43:13: error: two or more data types in declaration of 'i'
   43 |         for(ll int i=1;i<=n;i++){
      |             ^~
a.cc:43:24: error: 'i' was not declared in this scope
   43 |         for(ll int i=1;i<=n;i++){
      |                        ^
a.cc:44:23: error: 'ans' was not declared in this scope; did you mean 'abs'?
   44 |                 cout<<ans[i]<<endl;
      |                       ^~~
      |                       abs