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++. ...
随机推荐
- Python安装常见问题(1):zipimport.ZipImportError: can't decompress data
在CentOS以及其他的Linux系统中遇到安装包安装错误的原因,大多数都是因为缺少依赖包导致的,所以对于错误:zipimport.ZipImportError: can’t decompress d ...
- __import__ 与动态加载 python module
原文出处: koala bear Direct use of __import__() is rare, except in cases where you want to import a m ...
- 阿里云小规模web集群分享(电商)
计算基础资源使用阿里云ECS.OSS.RDS.mysql中间件.CDN 原则是尽量少改动代码来实现web集群 1.负载均衡器: a)负责处理所有请求 b)http动态请求分配到后端web服务器 c)维 ...
- Mybatis的多对多映射
一.Mybatis的多对多映射 本例讲述使用mybatis开发过程中常见的多对多映射查询案例.只抽取关键代码和mapper文件中的关键sql和配置,详细的工程搭建和Mybatis详细的流程代码可参见& ...
- javascript本地,宿主,内置对象
一.本地对象:官方定义的对象独立于宿主环境的 ECMAScript 实现提供的对象,包括操作系统和浏览器.本地对象就是 ECMA-262 定义的类(引用类型).“本地对象”包含内容: Object ...
- Floyd 判圈算法
Floyd 判圈算法 摘自维基百科, LeetCode 上 141题 Linked List Cycle 用到这个, 觉得很有意思. 记录一下. 链接: https://zh.wikipedia.or ...
- Log4net 乱码问题解决
在将log4net输出到UdpAppender会出现乱码问题,当然,丢到第三方日志分析工具glaylog下,也出现中文乱码. <?xml version="1.0"?> ...
- html07
1.复习js的外部对象,DOM,BOMBOM window -location -Location对象 : href reload() -history -History :back() forwar ...
- Twitter OA prepare: K-complementary pair
2sum的夹逼算法,需要sort一下.本身不难,但是tricky的地方在于允许同一个数组元素自己跟自己组成一个pair,比如上例中的[5, 5].而且数组本身就允许值相等的元素存在,在计算pair时, ...
- ubuntu shell脚本出错 dash
今天在Ubuntu下调试代码,明明是正确的,却仍然报错,查了错误信息才知道:Ubuntu中默认不是bash,而是为了加快开机速度,使用了dash. dash中需要严格的语法,而且与bash语法不同.例 ...