Under construction

Still being built. Things may change

Bessie's Snow Cow

Time limit2sMemory limit512 MB

Summary
Given a tree rooted at snowball 1, process subtree color-painting updates and report the sum of distinct colors per snowball over a queried subtree.
Level

Hard8 of 10

Topics
Tree, DFS, Segment tree, Hash map
Solved
No attempts yet

Problem

Snow has arrived on the farm, and as every winter, Bessie is building a snow cow. Usually she tries to make the sculpture look as much like a real cow as possible. This year she wants something more abstract and builds a sculpture shaped like a tree. It consists of NN snowballs (1≤N≤105)(1\le N\le 10^5) joined by N−1N-1 branches. Each branch connects a pair of snowballs, and there is exactly one path between any two snowballs.

Bessie added a nose to one snowball, which makes it the head of the snow cow. She calls this snowball number 1.

Bessie dyes parts of the sculpture by splashing buckets of colored dye onto snowballs. Colors are integers from 11 to 10510^5, and she has an unlimited supply of buckets for every color. When Bessie splashes a snowball xx with a color cc, every snowball in the subtree of xx also receives color cc. Snowball yy is in the subtree of xx when xx lies on the path from yy to snowball 1. A color stays on a snowball once it is applied. For example, if a snowball has colors [1,2,3][1,2,3] and Bessie splashes it with color 4, the snowball has colors [1,2,3,4][1,2,3,4].

The colorfulness of snowball xx is the number of distinct colors on xx. When Bessie asks about snowball xx, the answer is the sum of the colorfulness values of all snowballs in the subtree of xx. Find these sums at the times Bessie asks.

Input

The first line contains NN and the number of queries QQ (1≤Q≤105)(1\le Q\le 10^5).

Each of the next N−1N-1 lines contains two integers aa and bb, a branch between snowballs aa and bb (1≤a,b≤N)(1 \le a, b \le N).

Each of the last QQ lines is a query. A line of the form

1 x c

means Bessie splashes dye of color cc on snowball xx, coloring every snowball in its subtree. A line of the form

2 x

asks for the sum of colorfulness values in the subtree of snowball xx. Here 1≤x≤N1\le x\le N and 1≤c≤1051\le c\le 10^5.

Output

For each query of type 2, print the sum of colorfulness values in the corresponding subtree. Use 64-bit integers to avoid overflow.

Hint

After the first type 1 query, snowball 4 is dyed with color 1.

After the second type 1 query, snowballs 4 and 5 are dyed with color 1.

After the third type 1 query, all snowballs are dyed with color 1.

Examples1

  1. Example 1

    Input
    5 18
    1 2
    1 3
    3 4
    3 5
    1 4 1
    2 1
    2 2
    2 3
    2 4
    2 5
    1 5 1
    2 1
    2 2
    2 3
    2 4
    2 5
    1 1 1
    2 1
    2 2
    2 3
    2 4
    2 5
    
    Expected output
    1
    0
    1
    1
    0
    2
    0
    2
    1
    1
    5
    1
    3
    1
    1