Automorphism

루트가 있는 트리에 리프를 추가하는 연산과, 주어진 정점의 서브트리 자기동형사상 개수를 998244353으로 나눈 나머지를 구하는 연산을 처리한다.

보통6트리DFS조합론수학아직 제출이 없습니다시간 제한8초메모리 제한512 MB

문제

You are given a rooted tree. Initially, it contains one vertex labeled as 11.

Your task is to process mm operations of two types:

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

As the numbers can be very large, find them modulo 998,244,353998\\,244\\,353.

For a rooted tree, whose root is rr and vertex set is SS, the automorphism is a bijection f:SSf: S \to S such that f(r)=rf(r) = r and u,vS\forall u, v \in S, f(u)f(u) is the parent of f(v)f(v) if and only if uu is the parent of vv.

입력

The first line contains one integer mm (1m31051 \leq m \leq 3 \cdot 10^5).

In the following mm lines, each line indicates an operation.
Each of these lines contains two integers tt and xx (0t10 \leq t \leq 1).

If t=0t = 0, add a new vertex labeled by the current maximum label plus 11. Add an edge between this new vertex and the vertex xx.

If t=1t = 1, calculate the number of automorphisms of the subtree of vertex xx.

It is guaranteed that, for each operation, the value of xx is between 11 and the current maximum label.

출력

For each calculate operation, print a single line with the number of automorphisms modulo 998,244,353998\\,244\\,353.