题意:

  就是找出所有环的个数, 但这个环中的每个点都必须只在一个环中

解析:

  在找环的过程中 判断度数是否为2就行。。。emm。。。

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + , INF = 0x7fffffff; int n, m, s, t, flag;
vector<int> G[maxn];
int vis[maxn], res;
void dfs(int u, int fa)
{
vis[u] = ;
for(int i=; i<G[u].size(); i++)
{
int v = G[u][i];
if(v == fa) continue;
if(vis[v])
{
s = v;
if(G[u].size() != ) flag = ;  //判断是否在一个简单环中
return;
}
else
{
dfs(v, u);
if(G[u].size() != ) flag = ;
break;
}
}
if(flag == && s == u)
res++;
} int main()
{
int u, v;
res = ;
cin >> n >> m;
for(int i=; i<m; i++)
{
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
for(int i=; i<=n; i++)
{
if(!vis[i])
{
s = INF, flag = ;
dfs(i, -);
}
}
cout << res << endl; return ;
}

Cyclic Components CodeForces - 977E(找简单环)的更多相关文章

  1. Cyclic Components CodeForces - 977E(DFS)

    Cyclic Components CodeForces - 977E You are given an undirected graph consisting of nn vertices and  ...

  2. CF 977E Cyclic Components

    E. Cyclic Components time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  3. 【codeforces div3】【E. Cyclic Components】

    E. Cyclic Components time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  4. 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 ...

  5. ReferenceError: Error #1069: 在 spark.components.RadioButtonGroup 上找不到属性 label,且没有默认值

    1.错误描写叙述 ReferenceError: Error #1069: 在 spark.components.RadioButtonGroup 上找不到属性 label,且没有默认值. at Ch ...

  6. 与班尼特·胡迪一起找简单规律(HZOJ-2262)

    与班尼特·胡迪一起找简单规律 Time Limit:  1 s      Memory Limit:   256 MB Description 班尼特·胡迪发现了一个简单规律 给定一个数列,1 , 1 ...

  7. POJ 3710 无向图简单环树上删边

    结论题,这题关键在于如何转换环,可以用tarjan求出连通分量后再进行标记,也可以DFS直接找到环后把点的SG值变掉就行了 /** @Date : 2017-10-23 19:47:47 * @Fil ...

  8. SPFA找负环(DFS) luogu3385

    SPFA找负环的基本思路就是如果一个点被访问两次说明成环,如果第二次访问时所用路径比第一次短说明可以通过一直跑这个圈将权值减为负无穷,存在负环 有bfs和dfs两种写法,看了一些博客,在bfs和dfs ...

  9. Codeforces 977E:Cyclic Components(并查集)

    题意 给出nnn个顶点和mmm条边,求这个图中环的个数 思路 利用并查集的性质,环上的顶点都在同一个集合中 在输入的时候记录下来每个顶点的度数,查找两个点相连,且度数均为222的点,如果这两个点的父节 ...

随机推荐

  1. nodeSelector + deamonset

    DaemonSet 配置文件的语法和结构与 Deployment 几乎完全一样,只是将 kind 设为 DaemonSet. 选择运行节点:当指定.spec.template.spec.nodeSel ...

  2. python获取文件扩展名的方法(转)

    主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧.具体实现方法如下: 1 2 3 4 import os.path def file_extension(path ...

  3. C#抽象类与抽象方法--就是类里面定义了函数而函数里面什么都没有做的类

    看一下代码应该就可以了 using System; using System.Collections.Generic; using System.Linq; using System.Text; na ...

  4. android so壳入口浅析

    本文转自http://www.9hao.info/pages/2014/08/android-soke-ru-kou-q 前言   开年来开始接触一些加固样本,基本都对了so进行了处理,拖入ida一看 ...

  5. C# Test Encryption and Decryption

    public MainWindow() { InitializeComponent(); Title = getUUID(); string s= httpGet("http://220.1 ...

  6. 20155210 Exp2 后门原理与实践

    20155210 Exp2 后门原理与实践 1.Windows获得Linux Shell 在windows下,打开CMD,使用ipconfig指令查看本机IP 如图: 然后使用ncat.exe程序,n ...

  7. 20155323刘威良《网络对抗》Exp8 Web基础

    20155323刘威良<网络对抗>Exp8 Web基础 实践内容 (1).Web前端HTML(0.5分) 能正常安装.启停Apache.理解HTML,理解表单,理解GET与POST方法,编 ...

  8. 20155333 《网络对抗》 Exp6 信息搜集与漏洞扫描

    20155333 <网络对抗> Exp6 信息搜集与漏洞扫描 基础问题 哪些组织负责DNS,IP的管理? 全球根服务器均由美国政府授权的ICANN统一管理,负责全球的域名根服务器.DNS和 ...

  9. Aspose.Cells.dll的用法

    public void OutExcel() { #region WorkbookDesigner designer = new WorkbookDesigner(); Worksheet sheet ...

  10. EZ 2018 05 13 NOIP2018 模拟赛(十三)

    这次的比赛真心水,考时估分240,然后各种悠闲乱逛 然后测完T1数组开小了炸成40,T2,T3都没开long long,T2炸成20,T3爆0 掉回1600+的深渊,但是还有CJJ dalao比我更惨 ...