Language: Java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Node {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int q = sc.nextInt();

		Node node[] = new Node[n];
		// 頂点の作成
		for (int i = 0; i < n; i++) {
			node[i] = new Node(i);
		}

		// 辺情報
		for (int i = 0; i < n - 1; i++) {
			int nodeA = sc.nextInt() - 1;
			int nodeB = sc.nextInt() - 1;

			node[nodeA].adjList.add(node[nodeB]);
			node[nodeB].adjList.add(node[nodeA]);
		}

		// 親方向の隣接情報を消す
		removeParent(0, node);

		/*
		for (int i = 0; i < n; i++) {
			printDebug(node[i]);
		}
		*/

		// カウンター計算
		for (int i = 0; i < n - 1; i++) {
			int subRoot = sc.nextInt() - 1;
			int count = sc.nextInt();

			node[subRoot].count += count;
		}

		for (int i = 0; i < n; i++) {
			System.out.print(node[i].count + " ");
			for (Node adj : node[i].adjList) {
				adj.count += node[i].count;
			}
		}
		System.out.println();
		sc.close();
	}

	private static void addCount(int subRoot, int count, Node[] node) {
		node[subRoot].count += count;
		for (Node child : node[subRoot].adjList) {
			addCount(child.id, count, node);
		}
	}

	private static void printDebug(Node node) {
		System.out.println("===============================");
		System.out.println("id  = " + node.id);
		System.out.print("adj = ");
		for (Node adj : node.adjList) {
			System.out.print(adj.id + " ");
		}
		System.out.println();
		System.out.println("count = " + node.count);
	}

	private static void removeParent(int id, Node[] node) {
		for (Node adj : node[id].adjList) {
			node[adj.id].adjList.remove(node[id]);
			removeParent(adj.id, node);
		}
	}

	static class Node {
		int id;
		List<Node> adjList;
		long count;

		// コンストラクタ
		public Node(int id) {
			this.id = id;
			this.adjList = new ArrayList<Node>();
			this.count = 0;
		}
	}

}


Compiler output:
Main.java:5: error: class Node is public, should be declared in a file named Node.java
public class Node {
       ^
Main.java:80: error: class Node is already defined in package unnamed package
	static class Node {
	       ^
Main.java:29: error: incompatible types: Node.Node[] cannot be converted to Node[]
		removeParent(0, node);
		                ^
Main.java:56: error: cannot find symbol
		node[subRoot].count += count;
		             ^
  symbol:   variable count
  location: class Node
Main.java:57: error: cannot find symbol
		for (Node child : node[subRoot].adjList) {
		                               ^
  symbol:   variable adjList
  location: class Node
Main.java:64: error: cannot find symbol
		System.out.println("id  = " + node.id);
		                                  ^
  symbol:   variable id
  location: variable node of type Node
Main.java:66: error: cannot find symbol
		for (Node adj : node.adjList) {
		                    ^
  symbol:   variable adjList
  location: variable node of type Node
Main.java:70: error: cannot find symbol
		System.out.println("count = " + node.count);
		                                    ^
  symbol:   variable count
  location: variable node of type Node
Main.java:74: error: cannot find symbol
		for (Node adj : node[id].adjList) {
		                        ^
  symbol:   variable adjList
  location: class Node
Main.java:75: error: cannot find symbol
			node[adj.id].adjList.remove(node[id]);
			            ^
  symbol:   variable adjList
  location: class Node
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
10 errors