QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#18589. 樹複製

統計

對於一個有根樹 $A$ 以及一個大於或等於 $2$ 的整數 $B$,我們定義無根樹 $A * B$ 如下:

  • 將樹 $A$ 複製 $B$ 次,得到 $B$ 個樹 $A_1, A_2, \ldots, A_B$。對於所有 $1 \le i < B$,將 $A_i$ 的根與 $A_{i+1}$ 的根以一條邊相連。

給定一棵無根樹 $C$,請找出一個有根樹 $A$ 以及一個大於或等於 $2$ 的整數 $B$,使得 $C = A * B$。

題目保證給定的 $C$ 一定存在對應的 $A$ 與 $B$。

若存在多組解,輸出其中任意一組即可。

對於兩棵無根樹 $T_1$ 與 $T_2$,若忽略頂點編號後兩者的結構相同,則稱 $T_1 = T_2$。

範例

輸入格式 1

4
1 2
2 3
3 4

輸出格式 1

4
1

輸入格式 2

6
1 2
1 3
1 4
4 5
4 6

輸出格式 2

2
3
1 2
1 3

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.