CF638C.Road Improvement
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads.
In each city there is exactly one repair brigade. To repair some road, you need two teams based in the cities connected by the road to work simultaneously for one day. Both brigades repair one road for the whole day and cannot take part in repairing other roads on that day. But the repair brigade can do nothing on that day.
Determine the minimum number of days needed to repair all the roads. The brigades cannot change the cities where they initially are.
在贝尔兰有 n 座城市和 n−1 条双向道路。每条道路连接某一对城市,且从任意一座城市出发,仅通过给定的道路即可到达其他任意一座城市。
每座城市中恰好有一支维修队。要修复某条道路,需要位于该道路所连接的两座城市的两支维修队同时工作一整天。这两支维修队整日共同修复该条道路,当天无法参与其他道路的修复工作。但维修队在某天也可以选择不执行任何任务。
请确定修复所有道路所需的最少天数。维修队不能改变其初始所在的城市。
输入格式
The first line of the input contains a positive integer n (2 ≤ n ≤ 200 000) — the number of cities in Berland.
Each of the next n - 1 lines contains two numbers u__i, v__i, meaning that the i-th road connects city u__i and city v__i (1 ≤ u__i, v__i ≤ n, u__i ≠ v__i).
输入的第一行包含一个正整数 n(2 ≤ n ≤ 200000)—— 表示 Berland 的城市数量。
接下来的 n − 1 行中,每行包含两个数 ui、vi,表示第 i 条道路连接城市 ui 和城市 vi(1 ≤ ui,vi ≤ n,且 ui = vi)。
输出格式
First print number k — the minimum number of days needed to repair all the roads in Berland.
In next k lines print the description of the roads that should be repaired on each of the k days. On the i-th line print first number d__i — the number of roads that should be repaired on the i-th day, and then d__i space-separated integers — the numbers of the roads that should be repaired on the i-th day. The roads are numbered according to the order in the input, starting from one.
If there are multiple variants, you can print any of them.
首先输出整数 k —— 修复贝尔兰所有道路所需的最少天数。
接下来的 k 行中,按天描述每天应修复的道路。第 i 行首先输出整数 di —— 第 i 天应修复的道路数量,然后输出 di 个用空格分隔的整数 —— 这些整数表示第 i 天应修复的道路编号(道路编号按输入顺序从 1 开始编号)。
若存在多种可行方案,输出任意一种即可。
输入输出样例
输入#1
4 1 2 3 4 3 2
输出#1
2 2 2 1 1 3
输入#2
6 3 4 5 4 3 2 1 3 4 6
输出#2
3 1 1 2 2 3 2 4 5
说明/提示
In the first sample you can repair all the roads in two days, for example, if you repair roads 1 and 2 on the first day and road 3 — on the second day.
在第一个样例中,你可以在两天内修复所有道路,例如:第一天修复道路 1 和 2,第二天修复道路 3。
输入解题思路,AI测评打分。不知道怎么写?