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.

Input

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.

Output

Print the single number — the number of groups of students that will be kicked out from the club.

Examples

Input
3 3
1 2
2 3
3 1
Output
0
Input
6 3
1 2
2 3
3 4
Output
2
Input
6 5
1 4
2 4
3 4
5 4
6 4
Output
1

Note

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.

题意:

Anna和Maria要给小学生发鞋带,如果某位小学生的鞋带只跟一个人绑定,那就要踢出去,单独没和人绑定的不予理会,问最少需要几轮可以使所有人都是孤立的。

思路:

每次先处理鞋带与外界绑定数为1的,由于是无向图,无所谓出度入度,进行拓扑排序的同时,计算所进行的总轮数。

#include<bits/stdc++.h>
using namespace std;
int deg[],n,m;
vector<int>to[];
int topsort()
{
queue<int>qu;
int i,go=,sum=;
while(go)
{
go=;
for(i=;i<=n;i++)
if(deg[i]==)
{
qu.push(i);
go=;
}
while(!qu.empty())
{
int a=qu.front();
qu.pop();
deg[a]--;
for(i=;i<to[a].size();i++)
deg[to[a][i]]--;
}
if(go)sum++;
}
return sum;
}
int main()
{
ios::sync_with_stdio(false);
int u,v;
int i,j,k;
cin>>n>>m;
for(i=;i<=m;i++)
{
cin>>u>>v;
deg[u]++;deg[v]++;
to[u].push_back(v);
to[v].push_back(u);
}
cout<<topsort()<<endl;
return ;
}

最新文章

  1. Java 8函数编程轻松入门(四)方法引用
  2. Asp.Net WebForm和MVC同样优秀!
  3. SQL Server常用语句
  4. 使用EntityFramwork[6.1]进行级联保存的时候出现异常
  5. 多线程基础 (八)NSOperation相关
  6. 收藏本网站兼容火狐IE
  7. Android 开源简单控件
  8. Topcoder 多校T-shirt场
  9. Object-c学习之路九(字典(NSDictionary&amp;NSMutableDictionary))
  10. C++命名准则
  11. SVM与LR的比较
  12. mac解压缩
  13. c#全宇宙最牛的编程软件
  14. visual studio 中无法删除项目或者文件
  15. 了解AJAX
  16. 基于html5 plus + Mui 移动App开发(一)
  17. java界面--WePush-master 项目跑起来 -碰到的问题
  18. linux sed 用法
  19. 使用python脚本实现iOS图片资源压缩
  20. ArcGIS中的数据连接问题——数据类型不统一

热门文章

  1. 教你小三角,适用移动端等,解决移动端a标签的默认样式
  2. ActiveMQ相关:
  3. C语言string.h中常用字符函数介绍
  4. 基于zxing的二维码(网格)扫描
  5. shp文件导入mysql5.6.15
  6. 使用FMDB最新v2.3版本教程
  7. 41. First Missing Positive (sort) O(n) time
  8. vim使用常看
  9. 连接IBM MQ原因码报2035的错误解决办法
  10. 优秀的WEB前端开发框架:Bootstrap!