#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. thinkphp权限管理Rbac实例

    首先,先建立Rbac那五张表(用户表,角色表,节点表,权限表,角色-用户表),后面四张可以在thinkphp中Rbac类里直接复制. 第二步,根据需求往那五张表里插入数据,注意:节点表里的节点名称一定 ...

  2. [Java多线程] volatile 关键字正确使用方法

    volatile 变量具有 synchronized 的可见性特性,但是不具备原子特性,即多线程环境中,使用 volatile 关键字的变量仅可以保证不同线程读取变量时,可以读到最新修改的变量值,但是 ...

  3. 关于4Ps 、4Cs 、4Rs 、4Vs营销策略的内容及优劣比较

  4. 自动化测试框架selenium+java+TestNG——TestNG注解、执行、测试结果和测试报告

    TestNG是java的一个测试框架,相比较于junit,功能更强大和完善,我是直接学习和使用的TestNG就来谈下TestNG的一些特点吧. TestNG的特点 注解 TestNG使用Java和面向 ...

  5. WPF-悬浮在底部的导航

    先用Rectangle代替导航按钮,这个导航会悬浮在界面的底部,当鼠标移进导航按钮上的时候,按钮会放大,移出后恢复正常.   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 ...

  6. Local storage htm5

    使用本地存储,web应用可以在用户浏览器中本地存储数据. 在HTML5之前,应用数据存储必须使用cookie,包括每个服务端的请求,本地存储更加安全,并且可以存储大量的数据到本地,不影响网站的性能. ...

  7. BZOJ2599:[IOI2011]Race

    浅谈树分治:https://www.cnblogs.com/AKMer/p/10014803.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem. ...

  8. 在IIS6.0以上版本发布Ajax中,解决添加.v路径找不到的问题?

    问题描述:配置Aiax方式如下: 1.在AppCode中加入文件夹Ajax,加入两个类文件: Ajax.cs: using System; using System.Collections.Gener ...

  9. themeforest 免费模板

    http://www.im286.com/thread-9550365-1-1.html 官网:http://themeforest.net/item/elena-responsive-email-t ...

  10. 关于使用quartz动态增删改定时任务

    1. 首先, 还是喜闻乐见的导包 <dependency> <groupId>org.springframework.boot</groupId> <arti ...