atcoder#HITACHI2020F. Preserve Diameter

Preserve Diameter

Score : 11001100 points

Problem Statement

We have a tree GG with NN vertices numbered 11 to NN. The ii-th edge of GG connects Vertex aia_i and Vertex bib_i.

Consider adding zero or more edges in GG, and let HH be the graph resulted.

Find the number of graphs HH that satisfy the following conditions, modulo 998244353998244353.

  • HH does not contain self-loops or multiple edges.
  • The diameters of GG and HH are equal.
  • For every pair of vertices in HH that is not directly connected by an edge, the addition of an edge directly connecting them would reduce the diameter of the graph.

Constraints

  • 3N2×1053 \le N \le 2 \times 10^5
  • 1ai,biN1 \le a_i, b_i \le N
  • The given graph is a tree.

Input

Input is given from Standard Input in the following format:

NN

a1a_1 b1b_1

\vdots

aN1a_{N-1} bN1b_{N-1}

Output

Print the answer.

6
1 6
2 1
5 2
3 4
2 3
3

For example, adding the edges (1,5),(3,5)(1, 5), (3, 5) in GG satisfies the conditions.

3
1 2
2 3
1

The only graph HH that satisfies the conditions is GG.

9
1 2
2 3
4 2
1 7
6 1
2 5
5 9
6 8
27
19
2 4
15 8
1 16
1 3
12 19
1 18
7 11
11 15
12 9
1 6
7 14
18 2
13 12
13 5
16 13
7 1
11 10
7 17
78732