#P10064. [SNOI2024] 公交线路

[SNOI2024] 公交线路

Problem Description

Given an unrooted tree with nn nodes. We want to build bus routes between some pairs of nodes so that between any two nodes, it takes at most two bus routes to travel.

Formally, consider all n(n1)2\frac{n (n - 1)}{2} simple paths on the tree whose endpoints are different. For a subset SS of these paths, we call it good if and only if:

  • Consider a new graph GG. For a pair of nodes u,vu, v, if and only if there exists a path PP in SS such that both uu and vv lie on PP, we add an undirected edge of weight 11 between uu and vv.
  • Require that the distance between any two nodes in GG is at most 22.

You need to compute how many subsets SS are good. Since the answer may be large, output it modulo 998244353998244353.

Input Format

The first line contains a positive integer nn, the number of nodes.
The next n1n - 1 lines each contain two positive integers u,vu, v, representing a tree edge (u,v)(u, v).

Output Format

Output one integer, the answer modulo 998244353998244353.

3
1 2
2 3

5

6
1 2
2 3
2 4
3 5
3 6

27296

Hint

[Sample #1 Explanation]

For the first sample, all feasible plans 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 attachments bus/bus3.in and bus/bus3.ans.

This sample satisfies the constraints of testdata 111411 \sim 14.


[Sample #4]

See the attachments bus/bus4.in and bus/bus4.ans.

This sample satisfies the constraints of testdata 192019 \sim 20.


[Constraints]

For all testdata, it is guaranteed that 1n30001 \le n \le 3000.

Details are as follows:

Testdata ID nn \le Special Property
131 \sim 3 66 None
474 \sim 7 1010
8108 \sim 10 30003000 A
111411 \sim 14 100100 None
151815 \sim 18 500500
192019 \sim 20 30003000

Special property A: the tree is a chain.

Translated by ChatGPT 5