Codeforces Beta Round #94 div 2 B
2 seconds
256 megabytes
standard input
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.
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.
Print the single number — the number of groups of students that will be kicked out from the club.
3 3
1 2
2 3
3 1
0
6 3
1 2
2 3
3 4
2
6 5
1 4
2 4
3 4
5 4
6 4
1
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#define true ture
#define false flase
using namespace std;
#define ll __int64
#define inf 0xfffffff
int scan()
{
int res = , ch ;
while( !( ( ch = getchar() ) >= '' && ch <= '' ) )
{
if( ch == EOF ) return << ;
}
res = ch - '' ;
while( ( ch = getchar() ) >= '' && ch <= '' )
res = res * + ( ch - '' ) ;
return res ;
}
int du[];
int mapp[][];
int gg[];
int main()
{
int x,y,z,i,t,q;
scanf("%d%d",&x,&q);
while(q--)
{
int u,v;
scanf("%d%d",&u,&v);
du[u]++;
du[v]++;
mapp[u][v]=mapp[v][u]=;
}
int ans=;
while()
{
int ji=;
for(i=;i<=x;i++)
{
if(du[i]==)
gg[ji++]=i;
}
for(i=;i<ji;i++)
{
for(t=;t<=x;t++)
{
if(mapp[gg[i]][t])
{
mapp[gg[i]][t]=mapp[t][gg[i]]=;
du[gg[i]]--;
du[t]--;
}
}
}
if(!ji)
break;
ans++;
}
printf("%d\n",ans);
return ;
}
Codeforces Beta Round #94 div 2 B的更多相关文章
- 图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces
题目传送门 /* 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) */ #include <cstdio> #include <cs ...
- BFS Codeforces Beta Round #94 (Div. 2 Only) C. Statues
题目传送门 /* BFS:三维BFS,坐标再加上步数,能走一个点当这个地方在步数内不能落到.因为雕像最多8步就会全部下落, 只要撑过这个时间就能win,否则lose */ #include <c ...
- Codeforces Beta Round #94 (Div. 1 Only)B. String sam
题意:给你一个字符串,找第k大的子字符串.(考虑相同的字符串) 题解:建sam,先预处理出每个节点的出现次数,然后处理出每个节点下面的出现次数,然后在dfs时判断一下往哪边走即可,注意一下num会爆i ...
- 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 ...
- 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 ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
随机推荐
- Selenium之Css Selector使用方法
什么是Css Selector? Css Selector定位实际就是HTML的Css选择器的标签定位 工具 Css Selector的练习建议使用火狐浏览器,下载插件,FireFinder.Fire ...
- 纯代码实现WordPress上传图片自动重命名的方法
在我们使用 WordPress 发布文章时,经常都需要添加图片.多媒体什么的.然而,大家都知道 WordPress 是舶来物,对于中文用户来说,我们都会把图片命名为中文的,由于 WordPress 机 ...
- MySQL主从复制(Replication for Backup)
环境:MySQL5.7,VMware-Workstation-12-Pro,Windows-10,CentOS-7.5,Xshell5 1. 基本概念和操作思路 主从复制能做什么 数据库的主从复制,是 ...
- 字符串最长子串匹配-dp矩阵[转载]
转自:https://blog.csdn.net/zls986992484/article/details/69863710 题目描述:求最长公共子串,sea和eat.它们的最长公共子串为ea,长度为 ...
- CloudFlare CDN折腾记-优化设置
近期又在折腾了,常访问我博客的朋友或许页面曾出现过502错误提示,那是折腾CloudFlare CDN不成功的提示.在此先感谢坛子,在他的执着和求真之下,昨天晚上终于成功使用上CloudFlare C ...
- 表单验证——JqueryValidator、BootstrapValidator
表单验证两种方式: 1.JqueryValidator <!DOCTYPE html> <html lang="en"> <head> < ...
- 新浪微博 SAE
一.云平台中云是指互联网,网络的一种比喻说法,顾名思义,这种平台允许开发者们或是将写好的程序放在“云”里运行,或是使用“云”里提供的服务,或二者皆是. 二.开发类云平台比较: 1.鼻祖 GOOGLE ...
- css3 3d翻转效果
<div class="demo"> <span class="front"> aaaaaaaaaaa ...
- Object-C-复制
copy 减少对象上下文依赖 copy 创建一个新对象,copy得到的副本对象与原来内容相同,新的对象retain为1,与旧有对象的引用计数无关,旧有对象没有变化 使用 copy 创建出来的对象是不可 ...
- [SQL入门级] 这篇咱'薄利多销',记录多一点
这个系列的博文知识回顾sql知识作的记录,温故而知新.上一篇内容达不到知识分享的层级被移出园子首页,对不住各位看官,内容简单了些.下面咱就记录多一些的基础知识,薄利多销: 控制用户权限 • 创建用户 ...