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: import java.io.*;
import java.util.*;



class Edge{
	int s;
	int d;
	Edge(int s,int d){
		this.s = s;
		this.d = d;
	}
}
class Tree{
	LinkedList<Integer> node = new LinkedList<>();
}
class Main {
	public static void print(Tree tree[]){

		int i,n;
		n = tree.length;
		for(i=1;i<n;i++){
			LinkedList mlist = tree[i].node;
			System.out.print(i + " : ");
			for(Object val : mlist)
				System.out.print(val + " ");
			System.out.println();
		}
	}
	public static int calSum(Tree tree[],int data[],int p){

		int i;
		int n=data.length;
		if(n == 0)
			return 0;
		if(n == 1)
			return data[1];
		int level[] = new int[n];
		int visit[] = new int[n];
		Queue<Integer> queue = new LinkedList<>();
		queue.add(1);
		visit[1] = 1;
		while(queue.size() > 0){
			int val = queue.peek();
			queue.remove();
			int size = tree[val].node.size();
			for(i=0;i<size;i++){
				int d = tree[val].node.get(i);
				if(visit[d] == 0){
					level[d] = level[val] + 1;
					queue.add(d);
					visit[d] = 1;
				}
			}
		}
		int sum = 0;
		for(i=1;i<n;i++){
			if(level[i] == level[p])
				sum+=data[i];
		}
		return sum;
	}
	public static void main (String[] args) {

		int i,n,p,s,d;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		p = sc.nextInt();
		Tree tree[] = new Tree[n+1];
		Edge edge[] = new Edge[n];
		int data[] = new int[n+1];
		for(i=1;i<=n;i++)
			tree[i] = new Tree();
		for(i=1;i<n;i++){
			s = sc.nextInt();
			d = sc.nextInt();
			edge[i] = new Edge(s,d);
			tree[s].node.add(d);
			tree[d].node.add(s);
		}
		for(i=1;i<=n;i++)
			data[i] = sc.nextInt();


		int ans = calSum(tree,data,p);
		System.out.println(ans);
	}
}, In this Programming Language: Java, Now tell me if this Code is compilable or not?