Atcoder Grand Contest 032C(欧拉回路,DFS判环)
#include<bits/stdc++.h>
using namespace std;
int vis[100007];
vector<int>v[100007];
vector<int>vt;
int deg[100007];
void dfs(int a,int nev){//dfs判环
for(auto&x:v[a]){
if(!vis[x]&&x!=nev){//如果有不经过另一个度数为4的环,则图中定有三个环
vis[x]=1;
dfs(x,nev);
}
}
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
int a=0,b=0;
for(int i=1;i<=m;i++){
scanf("%d%d",&a,&b);
v[a].push_back(b);
v[b].push_back(a);
deg[a]++;
deg[b]++;
}
int flag=0;
for(int i=1;i<=n;i++){
if(deg[i]%2==1){//不是欧拉图直接否定
printf("No");
return 0;
}
if(deg[i]>=6)//度数大于等于6一定有三个环
flag=1;
if(deg[i]>=4)//分类讨论
vt.push_back(i);
}
if(flag){
printf("Yes");
return 0;
}
else{
if(vt.size()==2){//如果两个为度数为4的点之间有环
dfs(vt[0],vt[1]);
if(vis[vt[0]]){//有环
printf("Yes");
return 0;
}
}
else if(vt.size()>2){//图中有两个以上度数为4的点图中必定有三个环
printf("Yes");
return 0;
}
}
printf("No");
return 0;
}
Atcoder Grand Contest 032C(欧拉回路,DFS判环)的更多相关文章
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
- AtCoder Grand Contest 009
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...
- AtCoder Grand Contest 008
AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...
- AtCoder Grand Contest 006
AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...
- AtCoder Grand Contest 004
AtCoder Grand Contest 004 A - Divide a Cuboid 翻译 给定一个\(A*B*C\)的立方体,现在要把它分成两个立方体,求出他们的最小体积差. 题解 如果有一条 ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- AtCoder Grand Contest 007
AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...
- AtCoder Grand Contest 005
AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 ...
随机推荐
- matlab神经网络工具箱创建神经网络
为了看懂师兄的文章中使用的方法,研究了一下神经网络 昨天花了一天的时间查怎么写程序,但是费了半天劲,不能运行,百度知道里倒是有一个,可以运行的,先贴着做标本 % 生成训练样本集 clear all; ...
- composer 的设计原理及其基本用法
相信有在用PHP的朋友近年来常听到composer这个套件管理工具.它到底是做什么用的?又是为了解决什么问题而存在呢? 要了解这个,得先从历史开始说起…. PHP最早加载类的方法 初学PHP时,最早会 ...
- chart左侧
左侧单位 Chart1.Axes.Left.Minimum := ; Chart1.Axes.Left.Maximum := Series1.YValues.MaxValue * ; Chart1.A ...
- python的ftplib模块
Python中的ftplib模块 Python中默认安装的ftplib模块定义了FTP类,其中函数有限,可用来实现简单的ftp客户端,用于上传或下载文件 FTP的工作流程及基本操作可参考协议RFC95 ...
- HTML_基础篇
一.HTML的概述 什么是HTML? html:Hyper Test Markup Language 超文本标记语言(它不是编程语言!) 超文本:功能比普通的文本更加强大. 标记语言:使用一组标签对内 ...
- Redis搭建(三):哨兵模式
一.sentinel介绍 Redis 2.8中提供了“哨兵”工具来实现自动化的系统监控和故障恢复功能. Redis 2.6 版也提供了哨兵工具,但此时的哨兵是1.0版,存在非常多的问题,任何情况下都不 ...
- Spring总结四:IOC和DI 注解方式
首先我们要了解注解和xml配置的区别: 作用一样,但是注解写在Bean的上方来代替我们之前在xml文件中所做的bean配置,也就是说我们使用了注解的方式,就不用再xml里面进行配置了,相对来说注解方式 ...
- Tarjan的LCA离线算法
LCA(Least Common Ancestors)是指树结构中两个结点的最低的公共祖先.而LCA算法则是用于求两个结点的LCA.当只需要求一对结点的LCA时,我们很容易可以利用递归算法在O(n)的 ...
- Leetcode:Substring with Concatenation of All Words分析和实现
题目大意是传入一个字符串s和一个字符串数组words,其中words中的所有字符串均等长.要在s中找所有的索引index,使得以s[index]为起始字符的长为words中字符串总长的s的子串是由wo ...
- hibernate 框架的简单使用
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuratio ...