문제
Snow has arrived on the farm, and as she does at the beginning of every winter, Bessie is building a snow-cow! Most of the time, Bessie strives to make her sculpture look as much like a real cow as possible. However, feeling artistically inspired, this year she decides to pursue a more abstract route and build a sculpture in the shape of a tree, consisting of
Bessie has added a nose to one of the snowballs, so it represents the head of the abstract snow cow. She designates it as snowball number 1. To add more visual interest, she plans to dye some of the snowballs different colors in an artistic fashion by filling old milk pails with colored dye and splashing them onto the sculpture. Colors are identified by integers in the range
When Bessie splashes a snowball with a bucket of dye, all the snowballs in its subtree are also splashed with the same dye (snowball
After splashing the snowballs some number of times, Bessie may also want to know how colorful a part of her snow-cow is. The "colorfulness" of a snowball
Please help Bessie find the colorfulness of her snow-cow at certain points in time.
SCORING:
Test cases 2-3 satisfy
N\le 10^2, Q\le 2\cdot 10^2. Test cases 4-6 satisfy
N\le 10^3, Q\le 2\cdot 10^3.
Problem credits: Michael Cao and Benjamin Qi
입력
The first line contains
The next
Finally, the last
1 x c
indicates that Bessie splashed a bucket of juice of color
2 x
is a query for the sum of the colorfulness values of all snowballs in the subtree of
출력
For each query of type 2, print the sum of colorfulness values within the corresponding subtree. Note that you should use 64-bit integers to avoid overflow.
예제1
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
1
0
1
1
0
2
0
2
1
1
5
1
3
1
1
After the first query of type 1, snowball 4 is dyed with color 1.
After the second query of type 1, snowballs 4 and 5 are dyed with color 1.
After the third query of type 1, all snowballs are dyed with color 1.