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\)条边,问它们有多少个单环(无杂环),例如图中第二个就是一个杂环. 题解:不难发现,如果某几个点能够构成单环,那么每个点一定只能连两条边.所以我们先构建邻接表,然后 ...
随机推荐
- codeforces Codeforces Round #597 (Div. 2) B. Restricted RPS 暴力模拟
#include <bits/stdc++.h> using namespace std; typedef long long ll; ]; ]; int main() { int t; ...
- [lua]紫猫lua教程-命令宝典-L1-03-01. 闭包
L1[闭包]01. 函数的传递赋值 没什么说的 1.函数作为变量来看 可以轻松的声明 相互赋值 2.函数变量本质是 一个内存指针 所以函数变量的相互赋值不是传递的函数本身 而是指向这个函数的内存地址 ...
- 每天进步一点点------Allegro 手工布线时控制面板各选项说明
在进行手工布线过程中,最重要的就是对控制面板中的各个选项进行设置,因此首先介绍控制面板中各个选项的含义. 手工布线的命令为Route->connect,执行命令后,右侧控制面板如图8.14所示. ...
- active Directory域服务安装配置
1.在Windows功能启用 2.安装一直下一步即可, 添加用户 添加域管理员 将普通用户添加到Domain Admins里
- swagger2 常用注解的使用
一.@Api 效果: @Api注解放在类上面,这里的value是没用的,tags表示该controller的介绍. 二 .@ApiOperation 效果: @ApiOperation注解用于放在方法 ...
- POJ 2018 Best Cow Fences(二分答案)
题目链接:http://poj.org/problem?id=2018 题目给了一些农场,每个农场有一定数量的奶牛,农场依次排列,问选择至少连续排列F个农场的序列,使这些农场的奶牛平均数量最大,求最大 ...
- Advanced Architecture for ASP.NET Core Web API
转自: https://www.infoq.com/articles/advanced-architecture-aspnet-core ASP.NET Core's new architecture ...
- drf三大组件之认证组件与权限组件
复习 """ 视图家族 1.视图类:APIView.GenericAPIView APIView:作为drf的基础view:as_view()禁用csrf:dispatc ...
- Git提交时提示“Please make sure you have the correct access rights and the repository exists.”的解决方法
1.首先打开Git Bash设置名字和邮箱: git config --global user.name "你的名字" git config --global user.email ...
- c++工程编译记录
test3.c #include <stdio.h> #include <cpptest/cpptest.h> int test(int argc,char **argv); ...