RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0397 파일 입출력

Bessie's Snow Cow

Diamond V 다이아몬드 V
난이도
2s
시간 제한
256MB
메모리 제한
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 \(N\) snowballs
\((1\le N\le 10^5)\) connected by \(N-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
\(1 \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 \(y\) is in the subtree of
snowball \(x\) if \(x\) lies on the path from \(y\) 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]\) and Bessie splashes it with color \(4\), the snowball will
then have colors \([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 \(x\) is
equal to the number of distinct colors \(c\) such that snowball \(x\) is colored
\(c\). If Bessie asks you about snowball \(x\), you should reply with the sum of the
colorfulness values of all snowballs in the subtree of \(x.\)

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

Problem credits: Michael Cao and Benjamin Qi

제약

SCORING

\(Q\) is defined below.

  • 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 \(N,\) and the number of queries \(Q\) (\(1\le Q\le 10^5\)).

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

Finally, the last \(Q\) lines each contain a query. A query of the form

1 x c

indicates that Bessie splashed a bucket of juice of color \(c\) on snowball \(x,\)
coloring all snowballs in the subtree of \(x\). A line of the form

2 x

is a query for the sum of the colorfulness values of all snowballs in the
subtree of \(x\). Of course, \(1\le x\le N\) and \(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. **

파일 입력 / 출력
이 문제는 표준 입출력을 사용하지 않습니다. 프로그램은 다음 파일을 읽고 써야 합니다:
입력을 읽을 파일 snowcow.in
출력을 쓸 파일 snowcow.out
예제 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.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2019-2020 > December > Platinum

태그

평가 및 의견

Bessie's Snow Cow

개요
출제자 난이도 Diamond V 다이아몬드 V 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Bessie's Snow Cow

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8