QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#989. 进入仙人掌图

Statistics

给定一棵树,添加尽可能多的边,使得生成的图成为仙人掌图。

仙人掌图是指每条边最多包含在一个简单环中的图。该图不得包含自环或重边。

输入格式

第一行包含一个整数 $N$,表示树的大小 ($1 \le N \le 200\,000$)。

接下来的 $N - 1$ 行,每行包含两个整数 $u$ 和 $v$ ($1 \le u, v \le N, u \neq v$),表示节点 $u$ 和 $v$ 之间有一条边。保证给定的图是一棵树。

输出格式

第一行输出 $K$,表示可以添加到图中的最大边数。在接下来的 $K$ 行中,每行输出两个整数 $a$ 和 $b$ ($1 \le a, b \le N, a \neq b$),表示你将在节点 $a$ 和 $b$ 之间添加一条边。生成的图必须是仙人掌图。

如果存在多种达到最大值 $K$ 的方案,输出其中任意一种即可。

样例

样例输入 1

6
6 4
3 1
3 6
4 5
2 3

样例输出 1

2
2 1
3 5

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.