Logo
(追記) (追記ここまで)

19017번 - Automorphism 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
8 초 512 MB308624.000%

문제

You are given a rooted tree. Initially, it contains one vertex labeled as 1ドル$.

Your task is to process $m$ operations of two types:

  • Add a new vertex to the tree.
  • Calculate the number of automorphisms of the subtree rooted at vertex $u$.

As the numbers can be very large, find them modulo 998ドル,244円,353円$.

For a rooted tree, whose root is $r$ and vertex set is $S,ドル the automorphism is a bijection $f: S \to S$ such that $f(r) = r$ and $\forall u, v \in S,ドル $f(u)$ is the parent of $f(v)$ if and only if $u$ is the parent of $v$.

입력

The first line contains one integer $m$ (1ドル \leq m \leq 3 \cdot 10^5$).

In the following $m$ lines, each line indicates an operation.
Each of these lines contains two integers $t$ and $x$ (0ドル \leq t \leq 1$).

If $t = 0,ドル add a new vertex labeled by the current maximum label plus 1ドル$. Add an edge between this new vertex and the vertex $x$.

If $t = 1,ドル calculate the number of automorphisms of the subtree of vertex $x$.

It is guaranteed that, for each operation, the value of $x$ is between 1ドル$ and the current maximum label.

출력

For each calculate operation, print a single line with the number of automorphisms modulo 998ドル,244円,353円$.

제한

예제 입력 1

10
0 1
0 1
1 1
0 2
0 3
1 1
0 3
0 3
1 3
1 1

예제 출력 1

2
2
6
6

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2018 > Day 8: Yuhao Du Contest 5, Grand Prix of Zhejiang A번

Contest > Open Cup > 2018/2019 Season > Stage 1: Grand Prix of Zheijang A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /