For this Question: Given a tree consisting of N nodes (from 1 to N) rooted at 1. You are given a node, your task is to calculate the sum of values of all nodes present at the same level that is of the given node.First line of input contains two space separated integers denoting the number of nodes N and the given node P. Next N-1 lines contains two space separated integers U and V, denoting an edge of the tree. 
Last line of input contains N space separated integers denoting value of each node.

Constraints:-
2 <= N <= 10<sup>4</sup>
1 <= P <= N
1 <= U, V <= N
1 <= value[i] <= 10<sup>5</sup>Print the sum of all the nodes present at the same level as the node P.Sample Input:-
5 4
1 2
1 3
3 4
3 5
2 4 8 16 32

Sample Output:-
48

Explanation:-
  1
 / \
2   3
   / \
  4   5
Nodes present at same level as node 5 are:- 4 and 5, I have written this Solution Code: 
#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795
#define max1 1000001
#define MOD 1000000007

#define read(type) readInt<type>()

#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}

signed  main()
{
int n;
cin>>n;
vector<int> v[n];
int P;
cin>>P;
int a,b;
for(int i=0;i<n-1;i++){
    cin>>a>>b;
    a--;b--;
    v[a].EB(b);
    v[b].EB(a);
}
P--;
int ans[n];
FOR(i,n){
cin>>ans[i];
}
queue<int> q,p;
q.push(0);
bool check[n];
FOR(i,n){check[i]=false;}
int sum=0;
check[0]=true;
if(P==0){
out(ans[0]);
        return 0;
}
while(q.size()!=0){
    bool win=false;
    int s=q.size();

    for(int i=0;i<s;i++){
        a=q.front();
//out(a);
        for(int j=0;j<v[a].size();j++){
                if(check[v[a][j]]==false){
            if(v[a][j]==P){win=true;}
            p.push(v[a][j]);
            check[v[a][j]]=true;
            }
        }
        q.pop();
    }
    while(p.size()!=0){
        q.push(p.front());
        p.pop();
    }
    if(win){
        a=q.size();
        //out(a);
        FOR(i,a){
        sum+=ans[q.front()];
        q.pop();

        }
        break;
    }
}
out(sum);


}
, In this Programming Language: C++, Now tell me if this Code is compilable or not?