E. Cyclic Components (DFS)(Codeforces Round #479 (Div. 3))
#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))的更多相关文章
- 【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,输出任意方案. [算法]数学+搜索 [题解] 最关 ...
- 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 ...
- 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 ...
- 【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))最 ...
- D. Zero Quantity Maximization ( Codeforces Round #544 (Div. 3) )
题目链接 参考题解 题意: 给你 整形数组a 和 整形数组b ,要你c[i] = d * a[i] + b[i], 求 在c[i]=0的时候 相同的d的数量 最多能有几个. 思路: 1. 首先打开 ...
- 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 ...
- CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))
题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发 问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候 如果对于一条边 ...
- 贪心+构造( Codeforces Round #344 (Div. 2))
题目:Report 题意:有两种操作: 1)t = 1,前r个数字按升序排列: 2)t = 2,前r个数字按降序排列: 求执行m次操作后的排列顺序. #include <iostream&g ...
- 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 ...
随机推荐
- [RK3288][Android6.0] 调试笔记 --- 移除uboot和kernel开机logo【转】
本文转载自:http://blog.csdn.net/kris_fei/article/details/71600690 Platform: RockchipOS: Android 6.0Kernel ...
- LightOJ1138 —— 阶乘末尾0、质因子分解
题目链接:https://vjudge.net/problem/LightOJ-1138 1138 - Trailing Zeroes (III) PDF (English) Statistic ...
- Swing项目编译成exe,并且打包成安装文件(二)
前面我们讲到了将Swing项目编译成双击可执行的文件exe,这篇我就教大家怎么把exe打包成需要在电脑安装的那种,首先需要一个工具,Inno Setup 编译器, 下载地址,我这个是汉化版的,双击打开 ...
- Mysql数据库的打开和关闭
Mysql数据库的打开和关闭: 选择计算机(win7)-右键管理 在新窗口选择--服务 5 找到mysql,然后右键-启动(停止)
- Numpy 小结
Python 真火来学习一下,先来看一个库 NumPy.NumPy是Python语言的一个扩充程序库.支持高级大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库. 1. 读取文件 num ...
- AtCoder Grand Contest 014 E:Blue and Red Tree
题目传送门:https://agc014.contest.atcoder.jp/tasks/agc014_e 题目翻译 有一棵有\(N\)个点的树,初始时每条边都是蓝色的,每次你可以选择一条由蓝色边构 ...
- YoutubeAPI使用
YoutubeAPI使用 1 Youtube API能干什么 2 Youtube API 2.0 Youtube简介 2.1 如何使用Youtube API 2.1.1 获取Youtube 的开发 ...
- Code-NFine:NFine权限控制
ylbtech-Code-NFine:NFine权限控制 1.返回顶部 1. NFine框架研究 1.前台业务操作 1.1 系统菜单配置方法 1.2 菜单管理配置方法 1.2.1 按钮管理 1.2.2 ...
- tabbar
1 tabbar不显示的问题: 命名在app.json中配置了tabbar但是不显示可能的问题: app.json中的pages中第一个路径没有在tabbar中设置 原因:app.json中配置的pa ...
- HDOJ-1412(set)
{A} + {B} Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...