#P15721. [JAG 2023 Summer Camp #3] Many-hued Tree

[JAG 2023 Summer Camp #3] Many-hued Tree

题目描述

There is a tree with NN nodes numbered from 11 to NN. For each i=1,,N1i = 1, \ldots, N - 1, the ii-th edge connects node uiu_i and node viv_i.

You are going to paint all nodes in distinct colors. Colors are represented by integers between 11 and NN.

The assignment of colors on the tree is called good, if it is possible to complete the following operation N1N - 1 times repeatedly.

  • Select a pair of colors (A,B)(A, B) which satisfies the following two conditions.
    • AB=1|A - B| = 1.
    • There exists an edge which connects a node painted in color AA and a node painted in color BB.
  • Change the color of all nodes currently painted in color AA to color BB.

Your task is to count the number of good assignments of colors on the tree modulo 998,244,353998,244,353.

输入格式

The input consists of a single test case of the following format.

$$\begin{aligned} &N \\ &u_1 \ v_1 \\ &u_2 \ v_2 \\ &\vdots \\ &u_{N-1} \ v_{N-1} \end{aligned} $$

The first line consists of an integer NN, which satisfies 1N2,0001 \leq N \leq 2,000. Each of the N1N - 1 lines consists of two integers ui,viu_i, v_i, which satisfies 1ui,viN1 \leq u_i, v_i \leq N. The given graph is guaranteed to be a tree.

输出格式

Output in a line the number of assignments of colors on the given tree modulo 998,244,353998,244,353.

4
1 2
2 3
3 4
16
4
1 2
1 3
1 4
24