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\)条边,问它们有多少个单环(无杂环),例如图中第二个就是一个杂环. 题解:不难发现,如果某几个点能够构成单环,那么每个点一定只能连两条边.所以我们先构建邻接表,然后 ...
随机推荐
- 2020ICPC 博弈题 纳新一百的石子游戏
https://ac.nowcoder.com/acm/contest/4010/C 这道题为尼姆博弈的其中一种裸类型: 要求求出前(1~n)堆的必胜方案. 对于这种类型,假如我们现在就前k堆,那么我 ...
- C#中通过SendARP读取MAC地址
C#中通过SendARP读取MAC地址: using System.Runtime.InteropServices; publicstaticstring GetMacBySendARP(string ...
- 【转载】Hadoop面试(1)
转自:http://www.cnblogs.com/xiaolong1032/p/4504992.html 列举出hadoop常用的一些InputFormat InputFormat是用来对我们的输入 ...
- mutiprocessing 同步类型,如锁,条件和队列官方案例:
官方文档:https://docs.python.org/2/library/multiprocessing.html#module-multiprocessing 1. 同步类型,如锁,条件和队列官 ...
- 解决Cannot download "https://github.com/sass/node-sass/releases/download/binding.nod的问题
npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
- sql server获取查询时间
declare @d datetime set @d=getdate() /*你的SQL脚本开始*/ /*你的SQL脚本结束*/ select [语句执行花费时间(毫秒)]=datediff(ms,@ ...
- drf解析模块,异常模块,响应模块,序列化模块
复习 """ 1.接口:url+请求参数+响应参数 Postman发送接口请求的工具 method: GET url: https://api.map.baidu.com ...
- python的MySQLdb库基本使用介绍
MySQLdb库 import MySQLdb 简介 提供mysql的基本操作(包括建表,读取表数据,插入数据到表) 数据库操作基本步骤 #!/usr/bin/python # -*- coding: ...
- webstorm不能中文输入问题
版本:2018.1.4 原因:http://www.javatang.com/archives/2017/08/27/52101751.html 解决方案:https://www.cnblogs.co ...
- laravel5.1学习1-Model的创建
laravel5.1中可以很方便的用命令行创建Model 1.php artisan make:model Content 接着添加属性 $fillable =array('id','article_ ...