atcoder#ABC221F. [ABC221F] Diameter set

[ABC221F] Diameter set

Score : 500500 points

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.

5
1 2
1 3
1 4
4 5
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.

4
1 2
1 3
1 4
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.