#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. linux系统上安装svn服务器 环境linux+nginx+svnserver

    系统:Ubuntu 12.04 64位 lnmp环境 集成软件:PHP5.4.27.Nginx1.6.0.MySQL5.5.37 阿里云server svnserver有2种执行方式:独立server ...

  2. git branch 分支创建时间排序

    git branch日期排序 vi ~/.gitconfig [alias]lb = !"for k in `git branch -a|perl -pe s/^..//`;do echo ...

  3. Python pandas 获取Excel重复记录

    pip install pandas pip install xlrd 大量记录的时候,用EXCEL排序处理比较费劲,EXCEL程序动不动就无响应了,用pands完美解决. # We will use ...

  4. Proxy Pattern

    1.Proxy Pattern最大的好处就是实现了逻辑和实现的彻底解耦. 2.Proxy Pattern结构图 3.实现 #ifndef _PROXY_H_ #define _PROXY_H_ cla ...

  5. 关于mybatis的学习笔记

    配置文件 贴出mybatis的配置文件,这里mybatis还未与spring做整合: <?xml version="1.0" encoding="UTF-8&quo ...

  6. 在ubuntu16.04上编译android源码【转】

    本文转载自:http://blog.csdn.net/fuchaosz/article/details/51487585 1 前言 经过3天奋战,终于在Ubuntu 16.04上把Android 6. ...

  7. HDU2512 一卡通大冒险 —— 第二类斯特林数

    题目链接:https://vjudge.net/problem/HDU-2512 一卡通大冒险 Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  8. ping返回 dup

    大概原因如下: 目的主机不可达,也就是 跟主机不在一个网段,也没有路由跳转 一般是远端交换机或HUB流量超过负载,即堵塞 应该是你的网络中存在环路路由,也就是到达你ping的主机有一条以上的路由路径, ...

  9. UUID 和 GUID 的区别(转)

    UUID是一个由4个连字号(-)将32个字节长的字符串分隔后生成的字符串,总共36个字节长.比如:550e8400-e29b-41d4-a716-446655440000 http://gohands ...

  10. tkinter.py

    from tkinter import * def hello():print('hello world') win=Tk() win.title('hello tkinter') win.geome ...