Automorphism
시간 제한8초메모리 제한512 MB
루트가 있는 트리에 리프를 추가하는 연산과, 주어진 정점의 서브트리 자기동형사상 개수를 998244353으로 나눈 나머지를 구하는 연산을 처리한다.
문제
You are given a rooted tree. Initially, it contains one vertex labeled as .
Your task is to process operations of two types:
- Add a new vertex to the tree.
- Calculate the number of automorphisms of the subtree rooted at vertex .
As the numbers can be very large, find them modulo .
For a rooted tree, whose root is and vertex set is , the automorphism is a bijection such that and , is the parent of if and only if is the parent of .
입력
The first line contains one integer ().
In the following lines, each line indicates an operation.
Each of these lines contains two integers and ().
If , add a new vertex labeled by the current maximum label plus . Add an edge between this new vertex and the vertex .
If , calculate the number of automorphisms of the subtree of vertex .
It is guaranteed that, for each operation, the value of is between and the current maximum label.
출력
For each calculate operation, print a single line with the number of automorphisms modulo .