B. Students and Shoelaces
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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
  1. 3 3
    1 2
    2 3
    3 1
output
  1. 0
input
  1. 6 3
    1 2
    2 3
    3 4
output
  1. 2
input
  1. 6 5
    1 4
    2 4
    3 4
    5 4
    6 4
output
  1. 1
题意:给你N个点M条边的无向图;
   如果是环不管它,是树的话每次去掉根个树叶,问去掉的次数;
思路:就是暴力别想太多。。。
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<string>
  5. #include<queue>
  6. #include<algorithm>
  7. #include<stack>
  8. #include<cstring>
  9. #include<vector>
  10. #include<list>
  11. #include<set>
  12. #include<map>
  13. #define true ture
  14. #define false flase
  15. using namespace std;
  16. #define ll __int64
  17. #define inf 0xfffffff
  18. int scan()
  19. {
  20. int res = , ch ;
  21. while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
  22. {
  23. if( ch == EOF ) return << ;
  24. }
  25. res = ch - '' ;
  26. while( ( ch = getchar() ) >= '' && ch <= '' )
  27. res = res * + ( ch - '' ) ;
  28. return res ;
  29. }
  30. int du[];
  31. int mapp[][];
  32. int gg[];
  33. int main()
  34. {
  35. int x,y,z,i,t,q;
  36. scanf("%d%d",&x,&q);
  37. while(q--)
  38. {
  39. int u,v;
  40. scanf("%d%d",&u,&v);
  41. du[u]++;
  42. du[v]++;
  43. mapp[u][v]=mapp[v][u]=;
  44. }
  45. int ans=;
  46. while()
  47. {
  48. int ji=;
  49. for(i=;i<=x;i++)
  50. {
  51. if(du[i]==)
  52. gg[ji++]=i;
  53. }
  54. for(i=;i<ji;i++)
  55. {
  56. for(t=;t<=x;t++)
  57. {
  58. if(mapp[gg[i]][t])
  59. {
  60. mapp[gg[i]][t]=mapp[t][gg[i]]=;
  61. du[gg[i]]--;
  62. du[t]--;
  63. }
  64. }
  65. }
  66. if(!ji)
  67. break;
  68. ans++;
  69. }
  70. printf("%d\n",ans);
  71. return ;
  72. }

Codeforces Beta Round #94 div 2 B的更多相关文章

  1. 图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces

    题目传送门 /* 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) */ #include <cstdio> #include <cs ...

  2. BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues

    题目传送门 /* BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到.因为雕像最多8步就会全部下落, 只要撑过这个时间就能win,否则lose */ #include <c ...

  3. Codeforces Beta Round #94 (Div. 1 Only)B. String sam

    题意:给你一个字符串,找第k大的子字符串.(考虑相同的字符串) 题解:建sam,先预处理出每个节点的出现次数,然后处理出每个节点下面的出现次数,然后在dfs时判断一下往哪边走即可,注意一下num会爆i ...

  4. Codeforces Beta Round #94 div 1 D Numbers map+思路

    D. Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  5. Codeforces Beta Round #94 div 2 C Statues dfs或者bfs

    C. Statues time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  6. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  8. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  9. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

随机推荐

  1. html的img标签 强大的title

    示例: <img src="smiley-2.gif" alt="Smiley face" width="42" height=&qu ...

  2. 2018-2019-2 网络对抗技术 20165324 Exp5:MSF基础应用

    2018-2019-2 网络对抗技术 20165324 Exp5:MSF基础应用 MSF基础知识: MSF基础框架: 主要模块模块(Module).模块是指Metasploit框架中所使用的一段软件代 ...

  3. testng入门教程3用TestNG执行case的顺序

    本教程介绍了TestNG中执行程序的方法,这意味着该方法被称为第一和一个接着.下面是执行程序的TestNG测试API的方法的例子. 创建一个Java类文件名TestngAnnotation.java在 ...

  4. C++声明和定义

    目录 1 参考 2 概念 2.1 声明 2.2 定义 3 对比 3.1 声明但不是定义的情况 3.2 声明且是定义的情况 3.3 特殊情况 1. 参考 1. <C++程序设计语言>4.9 ...

  5. 【环境变量】Linux 下三种方式设置环境变量

    1.在Windows 系统下,很多软件安装都需要配置环境变量,比如 安装 jdk ,如果不配置环境变量,在非软件安装的目录下运行javac 命令,将会报告找不到文件,类似的错误. 2.那么什么是环境变 ...

  6. AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) Chapter 3. Data Structures Fundamental Data Structures

    10410 这题说的是给了一棵多叉树的 bfs遍历轨迹 和dfs 遍历 轨迹 在父节点向叶子节点扩展的时候优先遍历编号较小的节点.我还原出这课树特殊判定 根据bfs的顺序来建立这课树,用一个队列安排要 ...

  7. 使用IDEA 搭建SpringMVC +Easyui 实现最简单的数据展示功能

    效果图如下: 步骤如下: 1.导入jquery-easyui-1.5.5.6 2.导入相关的SpringMVC 的jar 包 3.编写datagrid.jsp 页面 <%-- Created b ...

  8. 我是怎么样和Linux结缘并通过红帽RHCE认证的

    我高考完当时就是选择的计算机科学与技术专业,上大学以后联想到的和计算机相关的就只有写代码,开发,网站,网页设计,就没有其他的了,当时学习写代码也都是在Windows上,什么C#.C++之类的?大约在大 ...

  9. Linux中Postfix邮件认证配置(五)

    Postfix+Dovecot+Sasl工作原理 1.A用户使用MUA客户端借助smtp协议登陆smtpd服务器,需要先进行用户和密码认证,而SMTPD服务器端支持sasl认证,例如有一个sasl客户 ...

  10. 微信小程序开发环境

    微信小程序开发环境 不忘初心,方得始终.初心易得,始终难守 小程序开发环境 开发工具下载地址:https://developers.weixin.qq.com/miniprogram/dev/devt ...