CF129B.Students and Shoelaces
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.
To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.
Determine how many groups of students will be kicked out of the club.
安娜和玛丽亚负责为低年级学生组织数学俱乐部。当俱乐部成员聚集在一起时,学生们表现得很差。他们带了许多鞋带到俱乐部,并用这些鞋带彼此绑在一起。具体来说,每根鞋带连接两名学生。此外,如果两名学生被绑在一起,则该鞋带既将第一名学生与第二名学生相连,也将第二名学生与第一名学生相连。
为了恢复秩序,安娜和玛丽亚执行如下操作:首先,安娜对每一名学生,找出与他相连的其他学生;若某学生恰好只与一名其他学生相连,则安娜会训斥他。接着,玛丽亚将所有刚刚被训斥的学生聚集为一个小组,并将他们逐出俱乐部。该小组的学生立即离开俱乐部,并带走所有曾用于捆绑他们的鞋带。随后,安娜再次对每一名剩余学生,统计他当前所连接的其他学生人数,并重复上述过程。如此反复,直至安娜无法再训斥任何一名学生为止。
请确定共有多少组学生会被逐出俱乐部。
输入格式
The first line contains two integers n and m — the initial number of students and laces (
). The students are numbered from 1 to n, and the laces are numbered from 1 to m. Next m lines each contain two integers a and b — the numbers of students tied by the i-th lace (1 ≤ a, b ≤ n, a ≠ b). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.
第一行包含两个整数 n 和 m —— 初始的学生人数和鞋带数量(
)。学生编号为 1 到 n,鞋带编号为 1 到 m。接下来的 m 行,每行包含两个整数 a 和 b —— 表示第 i 条鞋带所连接的两名学生的编号(1 ≤ a, b ≤ n,且 a = b)。保证任意两名学生之间至多由一条鞋带连接,且不存在连接学生自身的鞋带。
输出格式
Print the single number — the number of groups of students that will be kicked out from the club.
输出一个整数——将被踢出俱乐部的学生组的数量。
输入输出样例
输入#1
3 3 1 2 2 3 3 1
输出#1
0
输入#2
6 3 1 2 2 3 3 4
输出#2
2
输入#3
6 5 1 4 2 4 3 4 5 4 6 4
输出#3
1
说明/提示
In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one.
在第一个样例中,安娜和玛丽亚不会驱逐任何学生组——初始状态下,每名学生都与另外两名学生相连,因此安娜无法训斥任何人。
在第二个样例中,四名学生以链状方式相连,另有两名学生各自独立奔跑。首先,安娜和玛丽亚驱逐链状结构两端的学生(编号为 1 和 4),接着再驱逐链中剩下的两名学生(编号为 2 和 3)。此时,那两名各自独立奔跑的学生将留在俱乐部中。
在第三个样例中,安娜和玛丽亚会立即驱逐除第四名学生外的所有学生,过程随即终止。正确答案为 1。
输入解题思路,AI测评打分。不知道怎么写?