#arc171c. C - Swap on Tree

C - Swap on Tree

Score: 600600 points

问题陈述

有一棵包含 NN 个顶点的树,顶点编号为 11NN。第 ii 条边连接顶点 uiu_iviv_i。 此外,还有 NN 个编号为 11NN 的物品。最初,物品 ii 放置在顶点 ii 上。 你可以执行以下操作任意次数,可能为零次:

  • 选择一条边。设顶点 uuvv 是边的端点,并交换顶点 uuvv 上的物品。然后,删除所选的边。

设顶点 ii 上的物品为 aia_i。当你完成操作时,存在多少种不同的可能序列 (a1,a2,,aN)(a_1, a_2, \dots, a_N)?请计算出结果对 998244353998244353 取模后的值。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

There is a tree with NN vertices numbered 11 to NN. The ii-th edge connects vertices uiu_i and viv_i.
Additionally, there are NN pieces numbered 11 to NN. Initially, piece ii is placed on vertex ii.
You can perform the following operation any number of times, possibly zero:

  • Choose one edge. Let vertices uu and vv be the endpoints of the edge, and swap the pieces on vertices uu and vv. Then, delete the chosen edge.

Let aia_i be the piece on vertex ii. How many different possible sequences (a1,a2,,aN)(a_1, a_2, \dots, a_N) exist when you finish performing the operation? Find the count modulo 998244353998244353.

Constraints

  • 2N30002 \leq N \leq 3000
  • 1ui<viN1 \leq u_i \lt v_i \leq N
  • The graph given in the input is a tree.

Input

The input is given from Standard Input in the following format:

NN

u1u_1 v1v_1

u2u_2 v2v_2

\vdots

uN1u_{N-1} vN1v_{N-1}

Output

Print the number, modulo 998244353998244353, of possible sequences (a1,a2,,aN)(a_1, a_2, \dots, a_N).

Sample Input 1

3
1 2
2 3

Sample Output 1

5

For example, the sequence (a1,a2,a3)=(2,1,3)(a_1, a_2, a_3) = (2, 1, 3) can be obtained by the following steps:

  • Choose the first edge, swap the pieces on vertices 11 and 22, and delete the edge. This results in (a1,a2,a3)=(2,1,3)(a_1, a_2, a_3) = (2, 1, 3).
  • Finish operating.

Also, the sequence (a1,a2,a3)=(3,1,2)(a_1, a_2, a_3) = (3, 1, 2) can be obtained by the following steps:

  • Choose the second edge, swap the pieces on vertices 22 and 33, and delete the edge. This results in (a1,a2,a3)=(1,3,2)(a_1, a_2, a_3) = (1, 3, 2).
  • Choose the first edge, swap the pieces on vertices 11 and 22, and delete the edge. This results in (a1,a2,a3)=(3,1,2)(a_1, a_2, a_3) = (3, 1, 2).
  • Finish operating.

The operation can yield the following five sequences:

  • (1,2,3)(1, 2, 3)
  • (1,3,2)(1, 3, 2)
  • (2,1,3)(2, 1, 3)
  • (2,3,1)(2, 3, 1)
  • (3,1,2)(3, 1, 2)

Sample Input 2

5
2 5
3 4
1 3
1 5

Sample Output 2

34

Sample Input 3

8
4 5
2 5
3 6
1 3
1 8
2 7
2 8

Sample Output 3

799