atcoder#AGC058F. [AGC058F] Authentic Tree DP

[AGC058F] Authentic Tree DP

Score : 20002000 points

Problem Statement

For an undirected tree tt, let us define a rational number f(t)f(t) as follows.

  • Let nn be the number of vertices in tt.
  • If n=1n=1: Let f(t)=1f(t)=1.
  • If n2n \geq 2:- For an edge ee in tt, we denote by tx(e)t_x(e) and ty(e)t_y(e) the two trees that result from deleting ee from tt (in arbitrary order).
    • Let f(t)=(etf(tx(e))×f(ty(e)))/nf(t)=(\sum_{e \in t} f(t_x(e)) \times f(t_y(e)))/n.
  • For an edge ee in tt, we denote by tx(e)t_x(e) and ty(e)t_y(e) the two trees that result from deleting ee from tt (in arbitrary order).
  • Let f(t)=(etf(tx(e))×f(ty(e)))/nf(t)=(\sum_{e \in t} f(t_x(e)) \times f(t_y(e)))/n.

You are given a tree TT with NN vertices numbered 11 to NN. The ii-th edge connects Vertex AiA_i and Vertex BiB_i.

Find the value f(T)f(T) mod 998244353\text{mod }{998244353}.

What is a rational number $\text{mod }{998244353}$?

Under the Constraints of this problem, when the sought rational number is represented as PQ\frac{P}{Q}, it can be proved that Q0(mod998244353)Q \neq 0 \pmod{998244353}. Therefore, there is a unique integer RR such that $R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353$. Find this RR.

Constraints

  • 2N50002 \leq N \leq 5000
  • 1Ai,BiN1 \leq A_i,B_i \leq N
  • The given graph is a tree.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

AN1A_{N-1} BN1B_{N-1}

Output

Print the answer.

2
1 2
499122177

We have f(T)=1/2f(T)=1/2.

3
1 2
2 3
332748118

We have f(T)=1/3f(T)=1/3.

4
1 2
2 3
3 4
103983787
10
4 5
1 9
6 1
8 4
5 9
4 7
3 10
5 2
4 3
462781191