P27959 [洛谷] [SNOI2024] Bus Routes
省选
题目描述

Problem Description

Given an undirected tree with $n$ nodes, we want to establish bus routes between certain pairs of nodes such that any two nodes can be connected using at most two bus routes.

Formally, consider all $\frac{n (n - 1)}{2}$ simple paths with distinct endpoints in the tree. A subset $S$ of these paths is considered "good" if and only if:
- A new graph $G$ is constructed where for each pair of nodes $u, v$, an undirected edge with weight $1$ is added between $u$ and $v$ if and only if there exists a path $P$ in $S$ that contains both $u$ and $v$.
- The distance between any two nodes in $G$ is at most $2$.

You need to find the number of such "good" subsets $S$. Since the answer may be very large, output the result modulo $998244353$.

Input Format

The first line contains a single positive integer $n$, representing the number of nodes.
The next $n - 1$ lines each contain two positive integers $u$ and $v$, representing an edge in the tree between nodes $u$ and $v$.

Output Format

Output a single integer, which is the answer modulo $998244353$.

Sample Input and Output

Sample Input #1

3
1 2
2 3

Sample Output #1

5

Sample Input #2

6
1 2
2 3
2 4
3 5
3 6

Sample Output #2

27296

Notes

[Sample #1 Explanation]

For the first sample, the feasible schemes are $\{(1, 3)\}, \{(1, 3), (1, 2)\}, \{(1, 3), (2, 3)\}, \{(1, 3), (1, 2), (2, 3)\}, \{(1, 2), (2, 3)\}$.


[Sample #3]

See the attached files bus/bus3.in and bus/bus3.ans.

This sample satisfies the conditions for test points $11 \sim 14$.


[Sample #4]

See the attached files bus/bus4.in and bus/bus4.ans.

This sample satisfies the conditions for test points $19 \sim 20$.


[Data Range]

For all data, it is guaranteed that $1 \le n \le 3000$.

The specific data ranges are as follows:

Test Point $n \le$ Special Property
$1 \sim 3$ $6$ None
$4 \sim 7$ $10$ None
$8 \sim 10$ $3000$ A
$11 \sim 14$ $100$ None
$15 \sim 18$ $500$ None
$19 \sim 20$ $3000$ None

Special Property A: The tree is a chain.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 1 2 2 3
样例输出
5