QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 2048 MB

#22841. 最大直徑

Statistiques

設 $X = (x_1, x_2, \ldots, x_{n-1})$ 為任意一個長度為 $n - 1$、元素皆介於 $1$ 到 $n$ 之間(含兩端)的整數序列。考慮所有滿足下列條件的樹。這樣的樹總是至少存在一棵。定義 $f(X)$ 為這些樹中的最大直徑。

  • 該樹包含 $n$ 個節點,編號為 $1$ 到 $n$。邊編號為 $1$ 到 $n - 1$。對於每個 $i$($1 \le i \le n - 1$),邊 $i$ 的其中一個端點為 $x_i$。

此處,一棵樹的直徑是指兩個節點之間路徑上的最大邊數。

給定兩個整數序列 $A = (a_1, a_2, \ldots, a_{n-1})$ 與 $B = (b_1, b_2, \ldots, b_{n-1})$。$A$ 中的每個元素皆介於 $1$ 到 $n$ 之間(含兩端)。$B$ 中的每個元素皆為正整數。你可以假設數對 $(a_1, b_1), (a_2, b_2), \ldots, (a_{n-1}, b_{n-1})$ 皆互不相同。

對於每個 $d = 2, 3, \ldots, n - 1$,解決以下問題:

選擇一個元素皆介於 $1$ 到 $n$ 之間(含兩端)且滿足 $f(X) = d$ 的整數序列 $X = (x_1, x_2, \ldots, x_{n-1})$。這樣的序列總是存在。對於每個 $i$($1 \le i \le n - 1$),若且唯若 $x_i \ne a_i$ 時,你需要支付 $2^{b_i}$ 的成本。求最小可能的總成本。

由於每個答案可能很大,請將其除以 $998\,244\,353$ 取餘數後輸出。

輸入格式

輸入包含單一筆測試資料,格式如下。

$$ \begin{aligned} &n \\ &a_1 \ a_2 \ \cdots \ a_{n-1} \\ &b_1 \ b_2 \ \cdots \ b_{n-1} \end{aligned} $$

第一行包含一個整數 $n$($3 \le n \le 2 \times 10^5$)。第二行包含序列 $A$ 中的 $n - 1$ 個整數($1 \le a_i \le n$)。第三行包含序列 $B$ 中的 $n - 1$ 個整數($1 \le b_i \le 10^9$)。保證當 $i \ne j$ 時有 $(a_i, b_i) \ne (a_j, b_j)$。

輸出格式

輸出 $n - 2$ 行。第 $k$ 行應包含 $d = k + 1$ 時的答案,即滿足 $f(X) = k + 1$ 的序列 $X$ 之最小可能總成本除以 $998\,244\,353$ 的餘數。

範例

輸入格式 1

5
2 4 3 4
1 2 4 8

輸出格式 1

18
2
0

輸入格式 2

10
6 2 1 6 10 4 6 10 4
1 1 7 8 1 5 5 5 10

輸出格式 2

454
196
68
36
4
2
0
2

輸入格式 3

9
1 1 1 1 1 1 1 1
24 27 30 33 36 39 42 45

輸出格式 3

0
16777216
150994944
226492415
830472183
671088562
394263947

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#2902EditorialOpenNew Editorial for Problem #22841louyuxuanView

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.