QOJ.ac

QOJ

Time Limit: 8 s Memory Limit: 512 MB Total points: 100 Difficulty: [show]

#2203. Automorphism

Statistics

给定一棵有根树。初始时,树中仅包含一个标号为 1 的顶点。

你的任务是处理 $m$ 次操作,操作分为以下两种类型:

  • 向树中添加一个新顶点。
  • 计算以顶点 $u$ 为根的子树的自同构数量。

由于结果可能非常大,请输出其对 $998\,244\,353$ 取模的结果。

对于一棵根为 $r$、顶点集为 $S$ 的有根树,自同构是一个双射 $f : S \to S$,满足 $f(r) = r$,且对于任意 $u, v \in S$,$f(u)$ 是 $f(v)$ 的父节点当且仅当 $u$ 是 $v$ 的父节点。

输入格式

第一行包含一个整数 $m$ ($1 \le m \le 3 \cdot 10^5$)。

接下来的 $m$ 行,每行表示一个操作。每行包含两个整数 $t$ 和 $x$ ($0 \le t \le 1$)。

如果 $t = 0$,添加一个标号为当前最大标号加 1 的新顶点,并在该新顶点与顶点 $x$ 之间添加一条边。

如果 $t = 1$,计算以顶点 $x$ 为根的子树的自同构数量。

保证对于每次操作,$x$ 的值都在 1 和当前最大标号之间。

输出格式

对于每个计算操作,输出一行,表示子树的自同构数量对 $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

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.