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. Mavn 使用介绍

      1 Maven介绍 1.1 项目开发中遇到的问题 1.都是同样的代码,为什么在我的机器上可以编译执行,而在他的机器上就不行? 2.为什么在我的机器上可以正常打包,而配置管理员却打不出来? 3.项目 ...

  2. easyui numberbox输入框 编辑不可编辑的切换

    背景:申请单里需要选费用类型,费用类型有的有子明细项,有个合计项    当有子明细项的时候,合计项的值是通过弹出的子明细项价格的总和(设置为可编辑没问题,因为点击出来弹框,编辑不了)    没有子明细 ...

  3. VC添加文件到工程出错问题--FileTool.dll

    原文:http://blog.csdn.net/bingdianlanxin/article/details/45112737 在我们的软件开发中,经常需要导入其他文件到我们的工程. 一般,我们会选择 ...

  4. 139.00.004 Git学习-远程仓库之Github

    参考Github官方HelloWorld入门教程 "有了远程仓库,妈妈再也不用担心我的硬盘了."--Git点读机 本章开始介绍Git的杀手级功能之一(注意是之一,也就是后面还有之二 ...

  5. with优化妙用

    --语法: /*with   alias_name1 as    (subquery1),  alias_name2 as    (subQuery2),  ……  alias_nameN as   ...

  6. ZT————pull push mode

    谁能讲讲push和pull模式是什么意思?(参与有分) [问题点数:100分,结帖人mickeyfirst] 收藏 mickeyfirst mickeyfirst 等级: 结帖率:94.12% 楼主 ...

  7. 上海大智慧某站未授权访问&SQL注入

    详细说明: 注入:禁用JS,http://dzh.com.cn/admin/userlist.phphttp://dzh.com.cn/admin/editUser.php?username=test ...

  8. websphere8 从安装到部署 测试集群应用程序 安装j2ee程序(非常详细)

    目录1. 准备安装文件2. 安装Installation Manager3. 为Installation Manager指定安装资源库4. 创建部署管理器概要文件5. 创建定制概要文件并联合到部署管理 ...

  9. 「LG2664 树上游戏」

    题目 这真是一道神仙的一批的题目 定义\(s(i,j)\)表示从点\(i\)到点\(j\)经过的颜色数量 设 \[sum_i=\sum_{j=1}^ns(i,j)\] 求出所有的\(sum_i\) 考 ...

  10. JDBC(1)简单介绍/数据库的连接

    初识JDBC: JDBC是java连接数据库的一个工具,没有这个工具,java将无法和数据库进行连接. JDBC API: JDBC是个“低级”接口,也就是说,他直接用于调用SQL命令. JDBC驱动 ...