루트가 있는 트리에 리프를 추가하는 연산과, 주어진 정점의 서브트리 자기동형사상 개수를 998244353으로 나눈 나머지를 구하는 연산을 처리한다.
보통6트리DFS조합론수학아직 제출이 없습니다시간 제한8초메모리 제한512 MBYou are given a rooted tree. Initially, it contains one vertex labeled as 1.
Your task is to process m operations of two types:
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→S such that f(r)=r and ∀u,v∈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≤m≤3⋅105).
In the following m lines, each line indicates an operation.
Each of these lines contains two integers t and x (0≤t≤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.