QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#781. 三千世界

统计

問題背景

$n$ 個の頂点からなる木が与えられます。木のパスの集合 $S$ に対して、$f(S)$ を、$S$ に含まれるパスのうち、どの2つのパスも頂点を共有しない(頂点素である)ような最大のパスの集合 $T \subseteq S$ のサイズと定義します。 すべてのパスの集合 $P = \{(x, y) \mid 1 \le x, y \le n\}$ について、以下の総和を求めてください。

$$\sum_{S \subseteq P} f(S)$$

すなわち、$2^{n^2}$ 通りのすべてのパスの集合 $S$ についての $f(S)$ の総和を求めてください。答えは非常に大きくなる可能性があるため、998,244,353 で割った余りを出力してください。

入力形式

入力は以下の形式で標準入力から与えられる。

$n$ $u_1 \ v_1$ $u_2 \ v_2$ $\vdots$ $u_{n-1} \ v_{n-1}$

1行目には頂点数 $n$ が与えられる。 続く $n-1$ 行は木の辺を表し、$u_i, v_i$ は辺で結ばれた頂点である。

出力形式

条件を満たすパスの集合の総和を 998,244,353 で割った余りを一行に出力せよ。

入出力例

入力 1

2
1 2

出力 1

19

注記

$f$ 値が 0 となるのは $\emptyset$ の1通りです。$f$ 値が 2 となるのは $(1, 1)$ と $(2, 2)$ を含む場合であり、$(1, 2)$ と $(2, 1)$ の取り方で 4 通りあります。残りの 11 通りの集合は $f$ 値が 1 となるため、答えは $0 \times 1 + 1 \times 11 + 2 \times 4 = 19$ となります。

入力 2

5
1 2
2 3
3 4
4 5

出力 2

103767551

制約

すべてのデータにおいて $1 \le n \le 5,000$ を満たす。

テストケース $n$ 特殊制限
1 $= 2$
2 $= 3$
3 $= 4$
4 $= 5$
5, 6 $= 200$
7 $= 5,000$ A
8 $= 5,000$ B
9, 10 $= 5,000$

特殊制限: A:辺集合が $\{(1, 2), (2, 3), \dots, (n-1, n)\}$ である。 B:辺集合が $\{(1, 2), (1, 3), \dots, (1, n)\}$ である。

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.