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\)条边,问它们有多少个单环(无杂环),例如图中第二个就是一个杂环. 题解:不难发现,如果某几个点能够构成单环,那么每个点一定只能连两条边.所以我们先构建邻接表,然后 ...
随机推荐
- STM32F103之ADC学习记录
1.问题 1)10位ADC的误差是多少? 首先要分清分辨率与精度的区别. 10cm的尺子,有100个等分刻度,则该尺子的分辨率为1mm. 但不能说这把尺子的精度是1mm. 在冬天,尺子会热胀冷缩,依然 ...
- Apache Kafka(一)- Kakfa 简介与术语
Apache Kafka 1. Kafka简介.优势.以及使用场景 Kafka的优势: 开源 分布式,弹性架构,fault tolerant 水平扩展: 可以扩展到100个brokers 可以扩展到每 ...
- (转)Java中的String与常量池
Java中的String与常量池 转自:http://developer.51cto.com/art/201106/266454.htm string是java中的字符串.String类是不可变的,对 ...
- python numpy中sum()时出现负值
import numpy a=numpy.random.randint(1, 4095, (5000,5000)) a.sum() 结果为负值, 这是错误的,a.sum()的类型为 int32,如何做 ...
- 在同一个tomcat下部署多个springboot项目时,springboot项目无法正常启动的问题
这个问题是基于,不使用springboot内置的tomcat会产生(即使用自己的tomcat时). 今天在部署springboot项目的时候遇到了一个问题,怎么部署都访问不了,在网上查了很多原因,什么 ...
- springboot项目入门解析
config:主要用来存储配置文件,以及其他不怎么动用的信息. controller:项目的主要控制文件 dao: 主要用来操作数据库 entit ...
- Linux实现树莓派3B的国密SM9算法交叉编译——(一)环境部署、简单测试与eclipse工程项目测试
这篇文章主要介绍了交叉编译的实现,包括环境部署,并简单测试交叉编译环境是否安装成功. 一.交叉编译 在一个平台上生成另一个平台上的可执行代码.为什么要大费周折的进行交叉编译呢?一句话:不得已而为之.有 ...
- JavaScript复习总结一(入门)
总是执着想学各种框架,但忘了基础学好才最重要.每次打开菜鸟教程想重温基础内容,然后就像翻开英文字典,永远在abandon...还是需要做个笔记. 一来加深学习印象,二来等下次打开学习可以知道自己上次学 ...
- libcurl库的简介(二)
下面是使用libcurl库实现文件上传的一个实例: void CDataProcess::sendFileToServer(void) { string netIp = strNetUrl + &qu ...
- pyqt:布局删除小部件
参照:https://stackoverflow.com/questions/5899826/pyqt-how-to-remove-a-widget import sip layout.removeW ...