use std::io::*;

const SP: u8 = b' ';
const LF: u8 = b'\n';

struct CharacterInput<'a> {
    locked_stdin: StdinLock<'a>,
    bytes_buffer: Vec<u8>,
}

impl<'a> CharacterInput<'a> {
    fn read(&mut self, delimiter: u8) -> &[u8] {
        self.bytes_buffer.clear();

        let len = self
            .locked_stdin
            .read_until(delimiter, &mut self.bytes_buffer)
            .unwrap();

        let end_index = match self.bytes_buffer.last() {
            Some(byte) => {
                if *byte == delimiter {
                    len - 1
                } else {
                    len
                }
            }
            None => len,
        };

        &self.bytes_buffer[0..end_index]
    }

    fn scan_u(&mut self, delimiter: u8) -> u64 {
        self.read(delimiter)
            .into_iter()
            .fold(0, |accumulator, byte| {
                (byte - b'0') as u64 + accumulator * 10
            })
    }
}

fn create_cin<'a>(input: StdinLock<'a>, buffer_capacity: usize) -> CharacterInput {
    CharacterInput {
        locked_stdin: input,
        bytes_buffer: Vec::with_capacity(buffer_capacity),
    }
}

struct CharacterOutput {
    string_buffer: String,
}

impl CharacterOutput {
    fn push_s(&mut self, s: &str) {
        self.string_buffer += s;
    }

    fn push<T: ToString>(&mut self, n: T) {
        self.push_s(&n.to_string());
    }

    fn add<T: ToString>(&mut self, n: T, separator: char) {
        self.push(n);
        self.string_buffer.push(separator);
    }

    fn add_from_iterator<T: ToString, I>(
        &mut self,
        iterator: &mut I,
        length: usize,
        separator: char,
        delimiter: char,
    ) where
        I: Iterator<Item = T>,
    {
        for element in iterator.by_ref().take(length - 1) {
            self.add(element, separator);
        }
        self.add(iterator.next().unwrap(), delimiter);
    }

    fn flush(&mut self) {
        let out = stdout();
        let mut out = out.lock();
        out.write_all(self.string_buffer.as_bytes()).unwrap();
        self.string_buffer.clear();
    }
}

fn create_cout(capacity: usize) -> CharacterOutput {
    CharacterOutput {
        string_buffer: String::with_capacity(capacity),
    }
}

// ------------------------------------------------------------------------

trait GraphNode {
    fn get_adjacent_node_indices(&self) -> &Vec<usize>;
    fn add_adjacent_node(&mut self, index: usize);
}

fn scan_adjacent_nodes<T>(cin: &mut CharacterInput, edge_count: usize, node_list: &mut Vec<T>)
where
    T: GraphNode,
{
    for _i in 0..edge_count {
        let index_a = cin.scan_u(SP) as usize - 1;
        let index_b = cin.scan_u(LF) as usize - 1;
        node_list[index_a].add_adjacent_node(index_b);
        node_list[index_b].add_adjacent_node(index_a);
    }
}

use std::collections::VecDeque;

fn breadth_first_search<T, F>(
    nodes: &mut Vec<T>,
    n: usize,
    start_index: usize,
    visit_callback: &mut F,
) -> Option<usize>
where
    T: GraphNode,
    F: FnMut(usize, Option<usize>) -> bool,
{
    let mut node_visited_indicator_table = vec![false; n];

    let mut frontier_index_queue: VecDeque<usize> = VecDeque::with_capacity(n / 2);
    frontier_index_queue.push_back(start_index);

    let mut parent_index_queue: VecDeque<Option<usize>> = VecDeque::with_capacity(n / 2);
    parent_index_queue.push_back(None);

    loop {
        let node_index = frontier_index_queue.pop_front();
        let parent_index = parent_index_queue.pop_front();

        match node_index {
            Some(current) => {
                if visit_callback(current, parent_index.unwrap()) {
                    return Some(current);
                }

                for neighbor in nodes[current]
                    .get_adjacent_node_indices()
                    .iter()
                    .map(|rf| *rf)
                    .filter(|neighbor| node_visited_indicator_table[*neighbor] == false)
                {
                    frontier_index_queue.push_back(neighbor); // for_each() is not supported by v1.15.1
                    parent_index_queue.push_back(Some(current));
                }

                node_visited_indicator_table[current] = true;
            }
            None => break,
        }
    }

    None
}

struct Node {
    adjacent_node_indices: Vec<usize>,
}

impl GraphNode for Node {
    fn get_adjacent_node_indices(&self) -> &Vec<usize> {
        &self.adjacent_node_indices
    }

    fn add_adjacent_node(&mut self, index: usize) {
        self.adjacent_node_indices.push(index);
    }
}

fn main() {
    let cin = stdin();
    let cin = &mut create_cin(cin.lock(), 16);

    let n = cin.scan_u(SP) as usize;
    let q = cin.scan_u(LF) as usize;

    let mut node_list: Vec<Node> = (0..n)
        .map(|_| Node {
            adjacent_node_indices: Vec::new(),
        })
        .collect();

    scan_adjacent_nodes(cin, n - 1, &mut node_list);

    let mut proper_count_list: Vec<u64> = vec![0; n];

    for _ in 0..q {
        let p = cin.scan_u(SP) as usize;
        let x = cin.scan_u(LF);
        proper_count_list[p - 1] += x;
    }

    let mut total_count_list: Vec<u64> = vec![0; n];

    {
        let mut visit_callback = |node_index, parent_index| {
            match parent_index {
                Some(parent) => {
                    total_count_list[node_index] =
                        total_count_list[parent] + proper_count_list[node_index]
                }
                None => total_count_list[node_index] = proper_count_list[node_index],
            }
            return false;
        };

        breadth_first_search(&mut node_list, n, 0, &mut visit_callback);
    }

    let cout = &mut create_cout(n);
    cout.add_from_iterator(&mut total_count_list.iter(), n, ' ', '\n');
    cout.flush();
}


Measured memory_bytes: 29944