Language: C++

import java.util.*;
import java.lang.*;

public class Main{
	static Tree tree;
	static boolean[] visited;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		tree = new Tree(n);
		for (int i = 0; i < n - 1; i++) {
			tree.union(sc.nextInt() - 1, sc.nextInt() - 1);
		}
		for (int i = 0; i < q; i++) {
			tree.node[sc.nextInt() - 1].value += sc.nextInt();
		}
		visited = new boolean[n];
		visited[0] = true;
		dfs(0);
		for (int i = 0; i < n - 1; i++) {
			System.out.print(tree.node[i].value + " ");
		}
		System.out.println(tree.node[n - 1].value);
	}
	static void dfs(int n) {
		visited[n] = true;
		for (int key : tree.node[n].list) {
			if (!visited[key]) {
				visited[key] = true;
				tree.node[key].value += tree.node[n].value;
				dfs(key);
			}
		}
	}
}

class Node {
	ArrayList<Integer> list;
	int value;
	Node() {
		list = new ArrayList<>();
		value = 0;
	}
}

class Tree {
	Node[] node;
	Tree(int n) {
		node = new Node[n];
		for (int i = 0; i < n; i++) {
			node[i] = new Node();
		}
	}
	void union(int n, int m) {
		node[n].list.add(m);
		node[m].list.add(n);
	}
}


Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.lang.*;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: expected unqualified-id before 'public'
    4 | public class Main{
      | ^~~~~~
a.cc:39:9: error: 'ArrayList' does not name a type
   39 |         ArrayList<Integer> list;
      |         ^~~~~~~~~
a.cc:45:2: error: expected ';' after class definition
   45 | }
      |  ^
      |  ;
a.cc: In constructor 'Node::Node()':
a.cc:42:17: error: 'list' was not declared in this scope
   42 |                 list = new ArrayList<>();
      |                 ^~~~
a.cc:42:28: error: 'ArrayList' does not name a type
   42 |                 list = new ArrayList<>();
      |                            ^~~~~~~~~
a.cc:42:38: error: expected primary-expression before '>' token
   42 |                 list = new ArrayList<>();
      |                                      ^
a.cc:42:40: error: expected primary-expression before ')' token
   42 |                 list = new ArrayList<>();
      |                                        ^
a.cc: At global scope:
a.cc:48:13: error: expected unqualified-id before '[' token
   48 |         Node[] node;
      |             ^
a.cc:55:19: error: expected identifier before '(' token
   55 |         void union(int n, int m) {
      |                   ^
a.cc:55:20: error: expected unqualified-id before 'int'
   55 |         void union(int n, int m) {
      |                    ^~~
a.cc:55:20: error: expected ')' before 'int'
   55 |         void union(int n, int m) {
      |                   ~^~~
      |                    )
a.cc:59:2: error: expected ';' after class definition
   59 | }
      |  ^
      |  ;
a.cc: In constructor 'Tree::Tree(int)':
a.cc:50:17: error: 'node' was not declared in this scope; did you mean 'Node'?
   50 |                 node = new Node[n];
      |                 ^~~~
      |                 Node
a.cc:50:34: error: 'Node::Node()' is private within this context
   50 |                 node = new Node[n];
      |                                  ^
a.cc:41:9: note: declared private here
   41 |         Node() {
      |         ^~~~
a.cc:52:44: error: 'Node::Node()' is private within this context
   52 |                         node[i] = new Node();
      |                                            ^
a.cc:41:9: note: declared private here
   41 |         Node() {
      |         ^~~~