QOJ.ac

QOJ

时间限制: 1 s 内存限制: 32 MB 总分: 100

#11875. 字符串

统计

String-Toys 股份有限公司请求你帮助解决以下问题。他们想要制造由绳子构成的连通无环图模型。

每个图由顶点和连接不同顶点的若干条边组成。每个顶点可以连接多个其他顶点。如果从任意一个顶点出发,沿着边移动都能到达其他所有顶点,且路径唯一(不走回头路),则称该图为连通无环图(即树)。

图的顶点由绳子上的结来模拟,边则由连接结的绳子片段来模拟。每个节点既可以是一个绳子片段上的结,也可以是多个绳子片段打结在一起的点。由于技术原因,生产成本取决于制作模型所使用的绳子片段数量以及最长绳子片段的长度。(每条边的长度为 $1$。制作结所使用的绳子长度忽略不计。)

你需要编写一个程序,完成以下任务:

  • 从标准输入读取待建模的连通无环图的描述;
  • 计算:
    • 制作该模型所需的最少绳子片段数量;
    • 在绳子片段数量最少的前提下,制作该模型所需的最长绳子片段的最小长度;
  • 将得到的结果写入标准输出。

输入格式

第一行包含一个正整数 $n$,表示图中的顶点数,$2 \le n \le 10\,000$。顶点编号从 $1$ 到 $n$。接下来的 $n-1$ 行包含边的描述,每行一条。每行包含一对由空格分隔的整数 $a$ 和 $b$,$1 \le a, b \le n$,$a \ne b$。该数对表示连接顶点 $a$ 和 $b$ 的一条边。

输出格式

你的程序应在输出的第一行写入两个由空格分隔的整数 $k$ 和 $l$:$k$ 应为制作该图模型所需的最少绳子片段数量,$l$ 应为最长绳子片段的最小长度(假设使用了 $k$ 个绳子片段)。

样例

输入 1

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

输出 1

4 2

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.