#abc221f. F - Diameter set

F - Diameter set

Score : 500500 points

问题描述

给定一棵包含 NN 个顶点的树。这些顶点依次编号为 11, 22, \ldots, NN,对于每个 1iN11\leq i\leq N-1,第 ii 条边连接顶点 UiU_i 和顶点 ViV_i。令 DD 为这棵树的直径。求满足以下条件的不同红色顶点选择方案的数量(模 998244353998244353):选择两个或更多的顶点涂成红色,使得任意两个红色顶点之间的距离均为 DD

这里,两个顶点之间的距离是指从一个顶点到另一个顶点必须经过的最短边数,树的直径则是任意两个顶点之间最大距离。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Given is a tree with NN vertices. The vertices are numbered 11, 22, \ldots, NN, and for each 1iN11\leq i\leq N-1, the ii-th edge connects Vertex UiU_i and Vertex ViV_i. Let DD be the diameter of the tree. Find the number, modulo 998244353998244353, of ways to choose two or more of the vertices and paint them red so that all distances between two red vertices are DD.

Here, the distance between two vertices is the minimum number of edges that must be traversed to travel from one vertex to the other, and the diameter of the tree is the maximum distance between two vertices.

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • 1Ui,ViN1 \leq U_i,V_i \leq N
  • UiViU_i \neq V_i
  • All values in input are integers.
  • The given graph is a tree.

Input

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 answer.

Sample Input 1

5
1 2
1 3
1 4
4 5

Sample Output 1

2

The given tree has five vertices and a diameter of 33.
There are just two pairs of vertices whose distance is 33: (2,5)(2,5) and (3,5)(3,5), so there are two ways to paint the tree to satisfy the condition: {2,5}\lbrace 2,5\rbrace and {3,5}\lbrace 3,5\rbrace .
Note that painting 2,3,52,3,5 does not satisfy the condition since the distance between Vertex 22 and Vertex 33 is 22.

Sample Input 2

4
1 2
1 3
1 4

Sample Output 2

4

The diameter is 22, and the four ways to paint the tree to satisfy the condition are: {2,3}\lbrace 2,3\rbrace , {2,4}\lbrace 2,4\rbrace , {3,4}\lbrace 3,4\rbrace , {2,3,4}\lbrace 2,3,4\rbrace .

update @ 2024/3/10 09:45:33