#449
Unrated
Bessie's Snow Cow
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

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 NN snowballs (1N105)(1\le N\le 10^5) connected by N1N-1 branches, each connecting a pair of snowballs such that there is a unique path between every pair of snowballs.

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 11051 \ldots 10^5, and Bessie has an unlimited supply of buckets filled with dyes of every possible color.

When Bessie splashes a snowball with a bucket of dye, all the snowballs in its subtree are also splashed with the same dye (snowball yy is in the subtree of snowball xx if xx lies on the path from yy to the head snowball). By splashing each color with great care, Bessie makes sure that all colors a snowball has been splashed with will remain visible. For example, if a snowball had colors [1,2,3][1,2,3] and Bessie splashes it with color 44, the snowball will then have colors [1,2,3,4][1,2,3,4].

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 xx is equal to the number of distinct colors cc such that snowball xx is colored cc. If Bessie asks you about snowball xx, you should reply with the sum of the colorfulness values of all snowballs in the subtree of x.x.

Please help Bessie find the colorfulness of her snow-cow at certain points in time.

SCORING:

QQ is defined below.

Test cases 2-3 satisfy N102,Q2102.N\le 10^2, Q\le 2\cdot 10^2. Test cases 4-6 satisfy N103,Q2103.N\le 10^3, Q\le 2\cdot 10^3.

입력

The first line contains N,N, and the number of queries QQ (1Q1051\le Q\le 10^5).

The next N1N-1 lines each contain two space-separated integers aa and b,b, describing a branch connecting snowballs aa and bb (1a,bN1 \le a, b \le N).

Finally, the last QQ lines each contain a query. A query of the form

1 x c

indicates that Bessie splashed a bucket of juice of color cc on snowball x,x, coloring all snowballs in the subtree of xx. A line of the form

2 x

is a query for the sum of the colorfulness values of all snowballs in the subtree of xx. Of course, 1xN1\le x\le N and 1c105.1\le c\le 10^5.

출력

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

1
0
1
1
0
2
0
2
1
1
5
1
3
1
1
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.