#include <bits/stdc++.h>
using namespace std; const int maxn = *1e5+;
vector<int>p[maxn];
vector<int>c;
bool check[maxn]; void dfs(int x) {
check[x] = true;
c.push_back(x);
for (int i = ; i < p[x].size(); i++) {
int y = p[x][i];
if (!check[y]) {
dfs(y);
}
}
} int main() {
ios_base::sync_with_stdio(false);
cin.tie(); int n, m;
cin >> n >> m;
for (int i = ; i < m; i++) {
int u, v;
cin >> u >> v;
p[u].push_back(v);
p[v].push_back(u);
}
int ans = ;
for (int i = ; i <= n; i++) {
if (!check[i]) {
c.clear();
dfs(i);
bool flag = true;
for (int k = ; k < c.size(); k++) {
if (p[c[k]].size() != ) {
flag = false;
break;
}
}
if(flag)
ans++;
}
}
cout << ans << endl;
return ;
}

E. Cyclic Components (DFS)(Codeforces Round #479 (Div. 3))的更多相关文章

  1. 【CodeForces】841D. Leha and another game about graph(Codeforces Round #429 (Div. 2))

    [题意]给定n个点和m条无向边(有重边无自环),每个点有权值di=-1,0,1,要求仅保留一些边使得所有点i满足:di=-1或degree%2=di,输出任意方案. [算法]数学+搜索 [题解] 最关 ...

  2. B. Ohana Cleans Up(Codeforces Round #309 (Div. 2))

    B. Ohana Cleans Up   Ohana Matsumae is trying to clean a room, which is divided up into an n by n gr ...

  3. B. The Number of Products(Codeforces Round #585 (Div. 2))

    本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535 ...

  4. 【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))

    [题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最 ...

  5. D. Zero Quantity Maximization ( Codeforces Round #544 (Div. 3) )

    题目链接 参考题解 题意: 给你 整形数组a 和 整形数组b ,要你c[i] = d * a[i] + b[i], 求  在c[i]=0的时候  相同的d的数量 最多能有几个. 思路: 1. 首先打开 ...

  6. Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)

    C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...

  7. CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))

    题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发  问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候  如果对于一条边 ...

  8. 贪心+构造( Codeforces Round #344 (Div. 2))

    题目:Report 题意:有两种操作: 1)t = 1,前r个数字按升序排列:   2)t = 2,前r个数字按降序排列: 求执行m次操作后的排列顺序. #include <iostream&g ...

  9. A. Kyoya and Photobooks(Codeforces Round #309 (Div. 2))

    A. Kyoya and Photobooks   Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ...

随机推荐

  1. Ubuntu 12.04安装grub2过程中出错怎么办【转】

    本文转载自:https://zhidao.baidu.com/question/491448169666671012.html 其实是可以不用优盘启动的.但使用优盘没有风险.你的系统虽然出现==不能安 ...

  2. 数据结构之 字符串---字符串匹配(kmp算法)

    串结构练习——字符串匹配 Time Limit: 1000MS Memory limit: 65536K 题目描述   给定两个字符串string1和string2,判断string2是否为strin ...

  3. win7下使用source insight,没有Courier字体

    http://hi.baidu.com/raoxj/item/0e3a3a3b2461c5be134b14fa 1. “控制面板:--->“字体”--->找到Courier New(建议用 ...

  4. html5--3.16 button元素

    html5--3.16 button元素 学习要点 掌握button元素的使用 button元素 用来建立一个按钮从功能上来说,与input元素建立的按钮相同 button元素是双标签,其内部可以配置 ...

  5. plsql导入cvs 时提示missing right parenthesis

    删除自动生成的时间格式值,如:SQL function框里自动生成的值

  6. linux下mycat读写分离的配置

    为什么要配置读写分离,我想我就不需要再赘述了,那么在mycat下如何进行读写分离的配置,配置之后的实际效率又如何呢?我上午根据文档捣鼓和测试了一下,这里做一下记录: 最开始,我们还是要配置mysql本 ...

  7. 出现”/var/lib/mysql/mysql.sock“不存在的解决方法

    这种情况大多数是因为你的mysql是使用rpm方式安装的,它会自动寻找 /var/lib/mysql/mysql.sock 这个文件,通过unix socket登录mysql.常见解决办法如下:1.创 ...

  8. js 父组件向子组件传参

    有一个父组件页面如上,点击新增或者修改都会弹出同一个子组件如下: 父组件传参到子组件有两种方式: 一.直接把对象当成参数传给子组件,(看上去更简单,经测试发现一个问题,因为新增时要置空对象的所有信息, ...

  9. bzoj2750Road——最短路计数

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2750 以每个点作为源点,spfa跑出一个最短路图(不一定是树,因为可能很多条最短路一样长): ...

  10. web应用目录结构

    news web(应用的名字)||--静态资源和JSP文件都可以直接放在web应用的目录下,浏览器可以直接访问(html/jsp/css)|--WEB-INF 可以没有,但是最好有,一旦有,则结构需要 ...