QOJ.ac

QOJ

时间限制: 1.5 s 内存限制: 1024 MB 总分: 100 难度: [显示]

#8001. Bus Routes

统计

Given an unrooted tree with $n$ nodes, we wish to build bus routes between some pairs of nodes such that any two nodes can be reached using at most two bus routes.

Formally, consider all $\frac{n(n-1)}{2}$ simple paths between distinct endpoints in the tree. A subset $S$ of these paths is called "good" if and only if:

  • Consider a new graph $G$. For any pair of nodes $u, v$, we add an undirected edge with weight 1 between $u$ and $v$ if and only if there exists a path $P \in S$ such that both $u$ and $v$ are on $P$.
  • The distance between any two nodes in $G$ is at most 2.

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

Input

The first line contains a positive integer $n$, representing the number of nodes.

The next $n-1$ lines each contain two positive integers $u, v$, representing a tree edge $(u, v)$.

Output

Output a single integer representing the number of good subsets modulo 998244353.

Examples

Input 1

3
1 2
2 3

Output 1

5

Note

For the first example, all valid subsets are $\{(1, 3)\}$, $\{(1, 3), (1, 2)\}$, $\{(1, 3), (2, 3)\}$, $\{(1, 3), (1, 2), (2, 3)\}$, and $\{(1, 2), (2, 3)\}$.

Input 2

6
1 2
2 3
2 4
3 5
3 6

Output 2

27296

Constraints

For all data, $1 \le n \le 3000$.

The details are as follows:

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

Special Property A: The tree is guaranteed to be a chain.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#123EditorialOpen题解dXqwq2025-12-12 23:12:40View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.