Codeforce 977E Cyclic Components
dfs判断图的连通块数量~
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
const int maxn=1e6+;
vector<int> g[maxn];
int visit[maxn],N,M,x,y,flag;
void init () {
fill (visit,visit+maxn,);
for (int i=;i<maxn;i++) g[i].clear();
}
void dfs (int v) {
visit[v]=true;
if (g[v].size()!=) flag=;
for (int i=;i<g[v].size();i++)
if (!visit[g[v][i]]) dfs (g[v][i]);
}
int dfsTrave () {
int block=;
for (int i=;i<=N;i++)
if (!visit[i]) {
flag=;
dfs (i);
if (!flag) block++;
}
return block;
}
int main () {
while (~scanf ("%d %d",&N,&M)) {
init ();
for (int i=;i<M;i++) {
scanf ("%d %d",&x,&y);
g[x].push_back(y);
g[y].push_back(x);
}
printf ("%d\n",dfsTrave());
}
return ;
}
Codeforce 977E Cyclic Components的更多相关文章
- CF 977E Cyclic Components
E. Cyclic Components time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Cyclic Components CodeForces - 977E(DFS)
Cyclic Components CodeForces - 977E You are given an undirected graph consisting of nn vertices and ...
- 【codeforces div3】【E. Cyclic Components】
E. Cyclic Components time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforce Div-3 E.Cyclic Components
You are given an undirected graph consisting of nn vertices and mm edges. Your task is to find the n ...
- Codeforces 977E:Cyclic Components(并查集)
题意 给出nnn个顶点和mmm条边,求这个图中环的个数 思路 利用并查集的性质,环上的顶点都在同一个集合中 在输入的时候记录下来每个顶点的度数,查找两个点相连,且度数均为222的点,如果这两个点的父节 ...
- Cyclic Components CodeForces - 977E(找简单环)
题意: 就是找出所有环的个数, 但这个环中的每个点都必须只在一个环中 解析: 在找环的过程中 判断度数是否为2就行...emm... #include <bits/stdc++.h> us ...
- S - Cyclic Components (并查集的理解)
Description You are given an undirected graph consisting of nn vertices and mm edges. Your task is t ...
- E. Cyclic Components (DFS)(Codeforces Round #479 (Div. 3))
#include <bits/stdc++.h> using namespace std; *1e5+; vector<int>p[maxn]; vector<int&g ...
- Codeforces Round #479 (Div. 3) E. Cyclic Components (思维,DFS)
题意:给你\(n\)个顶点和\(m\)条边,问它们有多少个单环(无杂环),例如图中第二个就是一个杂环. 题解:不难发现,如果某几个点能够构成单环,那么每个点一定只能连两条边.所以我们先构建邻接表,然后 ...
随机推荐
- numpy特性
numpy特性 待办 可获取最小值最大值或者排序等操作的索引,然后通过索引取得对应值或者对应值的序列 按行按列求和.按行按列求积 方差等等统计函数使用 enter description here e ...
- CentOS之service iptables stop 显示not loaded
停止firewalld服务停止防火墙,并禁用这个服务 sudo systemctl stop firewalld.servicesudo systemctl disable firewalld.ser ...
- testng的prioriy
todo: 同一个class中的priority: 1.不标priority的case和标注priority的case,谁先谁后? 2.标注相同priority的case,谁先谁后?是不是并发? 3. ...
- linux php 扩展安装
phpize./configure --with-php-config=/usr/bin/php-config make && make install
- JavaWeb项目忘记添加依赖
有的时候我们建项目的时候忘记添加项目的依赖了,这里示范一个提示错误,就是 The superclass "javax.servlet.http.HttpServlet" was n ...
- java基础(八)之函数的复写/重写(override)
复写的意思就是子类对父类的修改. 复写的条件: 1.在具有父子类关系的两个类当中:2.父类和子类各有一个函数,这两个函数的定义保持一致(返回值类型.函数名.参数列表) 还是老样子,3个文件来说明. P ...
- redis架构
hash槽16384个,0-16383 master1(slave101,slave102) master2 (slave201,slave202) master 3 (slave30 ...
- vue Cli 按需引入Element UI 和全局引用Element UI
全局引用: 一.安装 Element UI npm i element-ui -S 二.在main.js 中引入 element UI import ElementUI from 'element-u ...
- 图片上传 一张展示,base64图片获取
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jquery 相同ID 绑定事件
本文链接:https://blog.csdn.net/lan_13217/article/details/84079441 http://hi.baidu.com/meneye/blog/item/1 ...