CF 129B - Students and Shoelaces
来源:互联网 发布:java double e 编辑:程序博客网 时间:2024/04/29 11:33
n个人,m对关系。每次能删除当前所有只跟一个人有关系的人,删到不能删要搞多少次。。。map+set不用想什么事,无脑拍就行了。。。
#include<iostream>#include<algorithm>#include<vector>#include<string>#include<stack>#include<cmath>#include<cstdio>#include<cstring>#include<cstdlib>#include<fstream>#include<map>#include<set>#define FF(i, a, b) for(i=a; i<b; i++)#define FD(i, a, b) for(i=a; i>b; i--)#define CLR(a, b) memset(a, b, sizeof(a))#define LL long longusing namespace std;int n, m;map<int, set<int> > s;set<int> tmp;set<int> :: iterator iter, it;int main(){ while(~scanf("%d%d", &n, &m)) { s.clear(); int a, b, ans = 0, flag = 1; while(m--) { scanf("%d%d", &a, &b); s[a].insert(b); s[b].insert(a); } while(flag) { flag = 0; tmp.clear(); FF(a, 1, n+1) { int k = s[a].size(); if(k == 1) { flag = 1; tmp.insert(a); } } if(flag) { for(iter=tmp.begin(); iter!=tmp.end(); iter++) { it = s[*iter].begin(); s[*it].erase(*iter); s[*iter].clear(); } ans++; } } printf("%d\n", ans); } return 0;}
- CF 129B - Students and Shoelaces
- B. Students and Shoelaces
- Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces
- CF B. Stadium and Games
- (CF)B. Sereja and Contests
- cf:B Kefa and Company
- CF--B. Wilbur and Array
- cf B. Wilbur and Array
- cf--B - Anatoly and Cockroaches
- CF C. Students' Revenge
- B. Anatoly and Cockroaches(CF B)
- CF 220B Little Elephant and Array
- CF 272B. Dima and Sequence
- CF 272 B. Dima and Sequence
- CF 272B Dima and Sequence
- [CF]295B. Greg and Graph | Floyd
- CF 314B: Sereja and Periods
- CF 313 B Ilya and Queries
- POJ 1185 炮兵阵地
- arm gcc工具链使用整理
- 快捷键的使用及命令提示符
- C#-------Graphics
- 不可掉以轻心!当心面试的最后5分钟
- CF 129B - Students and Shoelaces
- HDU 3074
- 分享职场心得《11》
- tesseract识别图片中文字(一)
- C语言面试问题集锦
- 百度绿萝2.0上线后,新站该如何做SEO?
- 还原AdventureWorks2008数据库FileStream错误
- stm32f4中用SD卡存储DCMI的图像
- 向Ubuntu Dash中添加图标