Problem:
Score : 400 points

Problem Statement

Given is a rooted tree with N vertices numbered 1 to N.
The root is Vertex 1, and the i-th edge (1 \leq i \leq N - 1) connects Vertex a_i and b_i.

Each of the vertices has a counter installed. Initially, the counters on all the vertices have the value 0.

Now, the following Q operations will be performed:

Operation j (1 \leq j \leq Q): Increment by x_j the counter on every vertex contained in the subtree rooted at Vertex p_j.

Find the value of the counter on each vertex after all operations.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq Q \leq 2 \times 10^5

1 \leq a_i < b_i \leq N

1 \leq p_j \leq N

1 \leq x_j \leq 10^4

The given graph is a tree.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q
a_1 b_1
:
a_{N-1} b_{N-1}
p_1 x_1
:
p_Q x_Q

Output

Print the values of the counters on Vertex 1, 2, \ldots, N after all operations, in this order, with spaces in between.

Sample Input 1

4 3
1 2
2 3
2 4
2 10
1 100
3 1

Sample Output 1

100 110 111 110

The tree in this input is as follows:

Each operation changes the values of the counters on the vertices as follows:

Operation 1: Increment by 10 the counter on every vertex contained in the subtree rooted at Vertex 2, that is, Vertex 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 0, 10, 10, 10, respectively.

Operation 2: Increment by 100 the counter on every vertex contained in the subtree rooted at Vertex 1, that is, Vertex 1, 2, 3, 4. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 110, 110, respectively.

Operation 3: Increment by 1 the counter on every vertex contained in the subtree rooted at Vertex 3, that is, Vertex 3. The values of the counters on Vertex 1, 2, 3, 4 are now 100, 110, 111, 110, respectively.

Sample Input 2

6 2
1 2
1 3
2 4
3 6
2 5
1 10
1 10

Sample Output 2

20 20 20 20 20 20

Solution in Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use libprocon::*;
use std::collections::HashSet;

#[derive(Debug, Clone)]
struct Node {
    children: Vec<usize>, // 子供の頂点番号を格納
    counter: usize,       // この頂点を根とする部分木に含まれるカウンターの値にどれだけ加算させるか
}

fn main() {
    input! {
        N: usize,
        Q: usize,
        ab: [(usize1, usize1); N-1],
        px: [(usize1, usize); Q],
    }
    let mut nodes = vec![
        Node {
            children: vec![],
            counter: 0
        };
        N
    ];
    for (a, b) in ab.into_iter() {
        nodes[a].children.push(b);
        // bがaの子供である保証はないため、逆向きの辺も張っておく
        nodes[b].children.push(a);
    }

    for (p, x) in px.into_iter() {
        nodes[p].counter += x;
    }

    let mut values = vec![0; N];
    let mut visited = HashSet::with_capacity(N);
    dfs(&nodes, 0, 0, &mut values, &mut visited);

    println!(
        "{}",
        values
            .into_iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}

fn dfs(
    nodes: &[Node],
    cur_node_number: usize,
    cur_value: usize,
    values: &mut Vec<usize>,
    visited: &mut HashSet<usize>,
) {
    let cur_node = &nodes[cur_node_number];
    visited.insert(cur_node_number);

    let updated_cur_value = cur_value + cur_node.counter;
    values[cur_node_number] = updated_cur_value;

    for &child_node_number in cur_node.children.iter() {
        if visited.contains(&child_node_number) {
            continue;
        }
        dfs(nodes, child_node_number, updated_cur_value, values, visited);
    }
}
*/

fn main() {
    let exe = "/tmp/bin56454E8A";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";