Under construction

Still being built. Things may change

Hyper Tree Problem

Time limit4sMemory limit1024 MB

Summary
Given a weighted tree, update edge weights with bitwise AND and report, for a query vertex, the sum over all vertices of the OR of edge weights on the path.
Level

Hard8 of 10

Topics
Bit manipulation, Union-find, Tree, Divide and conquer
Solved
No attempts yet

Problem

The tree has NN vertices numbered from 11 to NN, and its N−1N-1 edges are numbered from 11 to N−1N-1 in input order. Edge ii has weight WiW_i.

A total of QQ queries of two types are given. For each query of type 2, print the answer.

  • 1 e v: Change the weight WeW_e of edge ee to We&vW_e\And v. Here &\And is the Bitwise AND operation.
  • 2 n: Print ∑i=1Ndist(n,i)\sum_{i=1}^{N}{dist(n, i)}. dist(a,b)dist(a, b) is the Bitwise OR of all edge weights on the unique path between vertices aa and bb. If a=ba = b, then dist(a,b)=0dist(a, b) = 0.

Input

The first line contains NN and QQ, separated by a space. (2≤N≤300 000;1≤Q≤300 000)(2 \le N \le 300\ 000; 1 \le Q \le 300\ 000)

Each of the next N−1N-1 lines contains AiA_i, BiB_i, and WiW_i, separated by spaces. Edge ii connects vertices AiA_i and BiB_i, and its initial weight is WiW_i. (1≤Ai<Bi≤N;0≤Wi<220)(1 \le A_i < B_i \le N; 0 \le W_i < 2^{20})

Each of the next QQ lines is one of the following queries.

  • 1 e v: (1≤e<N;0≤v<220)(1 \le e < N; 0 \le v < 2^{20})
  • 2 n: (1≤n≤N)(1 \le n \le N)

All numbers in the input are integers. At least one query of type 2 is guaranteed.

Output

For each query of type 2, print the result on its own line, in the order the queries are given.

Examples1

  1. Example 1

    Input
    6 4
    3 4 1
    1 5 11
    3 5 13
    5 6 7
    2 5 0
    2 3
    1 3 10
    2 3
    2 2
    
    Expected output
    57
    43
    35