QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB

#23530. 系统发育树

Statistics

构建生物个体之间的系统发育关系是生物信息学中一项非常重要的工作。

系统发育关系通常用树表示,称为系统发育树。每个个体对应系统发育树中的一个叶节点。

系统发育树中两个叶节点之间的路径长度,表示对应的两个个体在进化上的亲近程度。

利用系统发育树,可以定义一个图,表示各个体在进化上的亲近程度。

这个图称为系统发育图。

相似度为 $K$ 的系统发育图定义如下。

图的每个顶点表示一个个体。两个顶点之间存在边,当且仅当系统发育树中与这两个顶点对应的节点之间的距离(路径长度)不超过 $K$。

某实验室构建了相似度为 $3$ 的系统发育图之后,丢失了系统发育树的数据。因此,现在要进行恢复系统发育树的工作。

给定一个相似度为 $3$ 的系统发育图,编写程序求出一棵定义该图的系统发育树。

注意,输入的系统发育图总是连通的,并且保证存在对应的系统发育树。

输入格式

第一行给出一个整数 $N$($2 \le N \le 5000$),表示系统发育图的顶点数。

顶点编号为 $1$ 到 $N$。

第二行给出一个整数 $M$($1 \le M \le 1000000$),表示系统发育图的边数。

接下来的 $M$ 行,每行给出两个整数 $v,w$($1 \le v,w \le N$),表示系统发育图中一条边的两个端点编号。

输出格式

第一行输出系统发育树的边数 $S$。

接下来的 $S$ 行,每行输出一条边的两个端点编号 $v$、$w$,中间用一个空格分隔。

树的边可以按任意顺序输出。

但树中编号 $1$ 到 $N$ 必须分配给叶节点。

另外,输入系统发育图中的顶点,与系统发育树中对应的叶节点,必须使用相同的编号。

其余内部节点可以任意使用 $N+1$ 到 $S+1$ 的编号。如果存在多棵系统发育树,只需求出并输出其中任意一棵。

样例

输入格式 1

6
7
1 2
2 3
3 1
3 4
3 5
5 6
6 3

输出格式 1

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

所有测试通过得 100 分,否则得 0 分。

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.