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 ;
}

【CodeForces 129 B】Students and Shoelaces(拓扑排序)的更多相关文章

  1. Codeforces Beta Round #29 (Div. 2, Codeforces format) C. Mail Stamps 离散化拓扑排序

    C. Mail Stamps Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem ...

  2. CodeForces 1213F (强联通分量分解+拓扑排序)

    传送门 •题意 给你两个数组 p,q ,分别存放 1~n 的某个全排列: 让你根据这两个数组构造一个字符串 S,要求: (1)$\forall i \in [1,n-1],S_{pi}\leq S _ ...

  3. (CodeForces 510C) Fox And Names 拓扑排序

    题目链接:http://codeforces.com/problemset/problem/510/C Fox Ciel is going to publish a paper on FOCS (Fo ...

  4. Educational Codeforces Round 25 E. Minimal Labels 拓扑排序+逆向建图

    E. Minimal Labels time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. Codeforces Round #292 (Div. 1) B. Drazil and Tiles 拓扑排序

    B. Drazil and Tiles 题目连接: http://codeforces.com/contest/516/problem/B Description Drazil created a f ...

  6. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  7. Codeforces Round #541 (Div. 2) D(并查集+拓扑排序) F (并查集)

    D. Gourmet choice 链接:http://codeforces.com/contest/1131/problem/D 思路: =  的情况我们用并查集把他们扔到一个集合,然后根据 > ...

  8. Codeforces Round #541 (Div. 2) D 并查集 + 拓扑排序

    https://codeforces.com/contest/1131/problem/D 题意 给你一个n*m二维偏序表,代表x[i]和y[j]的大小关系,根据表构造大小分别为n,m的x[],y[] ...

  9. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E. Tree Folding 拓扑排序

    E. Tree Folding 题目连接: http://codeforces.com/contest/765/problem/E Description Vanya wants to minimiz ...

随机推荐

  1. 12_Redis缓存穿透

    [何为缓存穿透] 缓存穿透是查询一个一定不存在的数据,这样的请求都要到存储层MySql去查询,失去了缓存的意义,在流量大时,可能MySql就挂掉了,要是有人利用不存在的key频繁攻击我们的应用,这就是 ...

  2. 深入理解mysql的底层实现

    MySQL 的常用引擎 1. InnoDB InnoDB 的存储文件有两个,后缀名分别是 .frm 和 .idb,其中 .frm 是表的定义文件,而 idb 是数据文件. InnoDB 中存在表锁和行 ...

  3. JBOSS参数调优

        阅读目录 JBOSS参数调优 jvm调优讲解1 JVM调优讲解2 JVM常见配置汇总 JBOSS生产环境下JVM调优 JBOSS瘦身 JBoss性能优化:内存紧张的问题终于解决了(转载)--- ...

  4. scrollview的总结

    今天主要是学习了cocos2dx的scrollview的内容,把简单的菜单滑动表现做出来了.像很多游戏的下方有一槽功能按钮,角色.背包.技能.帮助等,当宽度不足以全部显示出来的时候,隐藏一部分,以滑动 ...

  5. RESTful架构及SOA架构简单解析

    1.RESTful架构 本人也是刚接触ASP.NET开发,以下为自己简单的理解,并做了一些记录,表述不当或者错误之处还请指正,在此谢过. 首先,REST(REpresentational State  ...

  6. IIS 7.5+FCK编辑器+burp suite神器拿webshell

    本人小菜一枚,大牛勿喷 看图: 一个越南狗的网站,看了看好多人来过哦,估计都是在这跪下了,试了好多别人上传滴都不行,看了看是IIS7.5,难怪都卡在这里了,于是小编直接上神器Burp Suite- 截 ...

  7. SQLmap简介以及防火墙绕过方法

    简介 许多现实中对于网站的攻击往往是由于网站没有及时更新或者对于用户的输入没有进行检查.从缓冲区溢出说起,这样一种针对系统脆弱性的威胁,最根本的问题还是在于对于用户的输入没有进行检查.作为主要威胁之一 ...

  8. Service Fabric eShop On Containers

    Service Fabric承载eShop On Containers 从模块化到微服务化 从Pet Shop 到eShop on Container都是Microsoft在技术演进的路径上给开发者展 ...

  9. [零基础学JAVA]Java SE基础部分-03. 运算符和表达式

    转自:http://redking.blog.51cto.com/27212/116751 1.课程名称:运算符.表达式 讲解了JAVA中各种运算符的使用,包括与.或.非.大于.小于等. 2.知识点 ...

  10. html5 css3新特性了解一下

    html5: 用于绘画的 canvas 元素 以及SVG 用于媒介回放的 video 和 audio 元素 拖拽(Drag 和 drop) 地理定位(Geolocation) 对本地离线存储的更好的支 ...