Authentic Tree DP

AtCoder
IDagc058_f
Time2000ms
Memory256MB
Difficulty
For an undirected tree $t$, let us define a rational number $f(t)$ as follows. * Let $n$ be the number of vertices in $t$. * If $n=1$: Let $f(t)=1$. * If $n \geq 2$: * For an edge $e$ in $t$, we denote by $t_x(e)$ and $t_y(e)$ the two trees that result from deleting $e$ from $t$ (in arbitrary order). * Let $f(t)=(\sum_{e \in t} f(t_x(e)) \times f(t_y(e)))/n$. You are given a tree $T$ with $N$ vertices numbered $1$ to $N$. The $i$\-th edge connects Vertex $A_i$ and Vertex $B_i$. Find the value $f(T)$ $\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 $\frac{P}{Q}$, it can be proved that $Q \neq 0 \pmod{998244353}$. Therefore, there is a unique integer $R$ such that $R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353$. Find this $R$. ## Constraints * $2 \leq N \leq 5000$ * $1 \leq A_i,B_i \leq N$ * The given graph is a tree. ## Input Input is given from Standard Input in the following format: $N$ $A_1$ $B_1$ $A_2$ $B_2$ $\vdots$ $A_{N-1}$ $B_{N-1}$ [samples]
Samples
Input #1
2
1 2
Output #1
499122177

We have $f(T)=1/2$.
Input #2
3
1 2
2 3
Output #2
332748118

We have $f(T)=1/3$.
Input #3
4
1 2
2 3
3 4
Output #3
103983787
Input #4
10
4 5
1 9
6 1
8 4
5 9
4 7
3 10
5 2
4 3
Output #4
462781191
API Response (JSON)
{
  "problem": {
    "name": "Authentic Tree DP",
    "description": {
      "content": "For an undirected tree $t$, let us define a rational number $f(t)$ as follows. *   Let $n$ be the number of vertices in $t$. *   If $n=1$: Let $f(t)=1$. *   If $n \\geq 2$:     *   For an edge $e$ in ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc058_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "For an undirected tree $t$, let us define a rational number $f(t)$ as follows.\n\n*   Let $n$ be the number of vertices in $t$.\n*   If $n=1$: Let $f(t)=1$.\n*   If $n \\geq 2$:\n    *   For an edge $e$ in ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments