题:https://codeforces.com/problemset/problem/977/E

题意:给你一个图,问你有几个没有杂边的单环(度全为2)

分析:单环点的度数一定是2,连续边,判断是否连通,如果连通,ans++,否则连接这个边

#include<bits/stdc++.h>
using namespace std;
const int M=1e6+;
int f[M],a[M],b[M],du[M];
int findd(int x){
return x==f[x]?x:f[x]=findd(f[x]);
}
int main(){
int n,m,ans=;
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=;i<=n;i++)
f[i]=i;
for(int i=;i<=m;i++){
cin>>a[i]>>b[i];
du[a[i]]++;
du[b[i]]++;
}
for(int i=;i<=m;i++){
if(du[a[i]]==&&du[b[i]]==){
int x=findd(a[i]),y=findd(b[i]);
if(x==y)
ans++;
else
f[y]=x;
}
//cout<<"!!"<<endl;
}
cout<<ans<<endl;
return ;
}

CodeForces - 977E的更多相关文章

  1. Cyclic Components CodeForces - 977E(DFS)

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

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

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

  3. Cyclic Components CodeForces - 977E(找简单环)

    题意: 就是找出所有环的个数, 但这个环中的每个点都必须只在一个环中 解析: 在找环的过程中 判断度数是否为2就行...emm... #include <bits/stdc++.h> us ...

  4. Codeforces Round #479 (Div. 3) 题解 977A 977B 977C 977D 977E 977F

    A. Wrong Subtraction 题目大意:   定义一种运算,让你去模拟 题解:   模拟 #include <iostream> #include <cstdio> ...

  5. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  6. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  9. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

随机推荐

  1. Windows环境安装与搭建node.js环境

    参考文章:https://www.cnblogs.com/zhouyu2017/p/6485265.html 一.下载node.js,直接下一步至安装完成.https://nodejs.org/en/ ...

  2. Arduino - ( Uno、Nano、Promini)针脚示意图

    Uno针脚示意图 Nano针脚示意图 Promini针脚示意图

  3. 短网址资料-nginx非root用户启动-systemctl启动脚本-分割root权限

    https://www.cnblogs.com/aspnethot/articles/3492191.htmlhttps://www.cnblogs.com/aspnethot/articles/34 ...

  4. jQuery中的一些方法 19.5.20课上笔记

    after() insertAfter():特定元素后面插入新的节点 before() insertBefore():特定元素前面插入新的节点 append() appendTo():向特定元素元素内 ...

  5. vue组件化应用构建

    组件系统是 Vue 的另一个重要概念,因为它是一种抽象,允许我们使用小型.独立和通常可复用的组件构建大型应用.仔细想想,几乎任意类型的应用界面都可以抽象为一个组件树: 在 Vue 里,一个组件本质上是 ...

  6. RCE

    RCE remote command/code execute 远程系统命令/代码执行 系统从设计上需要给用户提供指定的远程命令操作的接口.可以测试一下自动运维平台. 在PHP中,使用system.e ...

  7. 深入理解Canvas Scaler

    Canvas Scaler: 这是一个理解起来相当繁琐复杂的一个组件,但又是一个至关重要的组件,不彻底了解它,可以说对UGUI的布局和所谓的“自适应”就没有一个完整的认识. Canvas Scale指 ...

  8. 理解Production- Ready特性

    1.外部配置(externalized configuration) 1).基于环境变量的配置 2).基于YAML的配置 3).默认配置值 2.健康检查(health checks) 1).它是否有一 ...

  9. part5 城市页面列表开发

    1.配置路由 先在router文件夹中,创建一个路由.引入组件 { path: '/city', name: 'HelloCity', component: city, meta: { name: ' ...

  10. GoF 23种设计模式概述

    本文的结构: 一.设计模式总览 二.创建型设计模式 Creational Patterns 三.结构型设计模式 Structural Patterns 四.行为型设计模式 Behavioral Pat ...