一笔画问题

时间限制:3000 ms  |  内存限制:65535 KB
难度:4

Position:http://acm.nyist.net/JudgeOnline/problem.php?pid=42

Description

zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来。

规定,所有的边都只能画一次,不能重复画。

Input

第一行只有一个正整数N(N<=10)表示测试数据的组数。
每组测试数据的第一行有两个正整数P,Q(P<=1000,Q<=2000),分别表示这个画中有多少个顶点和多少条连线。(点的编号从1到P)
随后的Q行,每行有两个正整数A,B(0<A,B<P),表示编号为A和B的两点之间有连线。

Output

如果存在符合条件的连线,则输出"Yes",
如果不存在符合条件的连线,输出"No"。
input
2 
4 3
1 2
1 3
1 4
4 5
1 2
2 3
1 3
1 4
3 4
output
No Yes

Solution

欧拉回路知识,(不懂请点击链接),无向连通图G含有欧拉通路(即一笔画),当且仅当G有零个或两个奇数度的结点;

Code

 // <42.cpp> - Wed Oct  5 11:56:45 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#pragma GCC push_options
#pragma GCC optimize ("O2")
#define MOD 1000000007
#define INF 1e9
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
typedef long double LB;
const int MAXN=;
const int MAXM=;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline LL gi() {
register LL w=,q=;register char ch=getchar();
while((ch<''||ch>'')&&ch!='-')ch=getchar();
if(ch=='-')q=,ch=getchar();
while(ch>=''&&ch<='')w=w*+ch-'',ch=getchar();
return q?-w:w;
}
struct Fleury{
static const int N=,M=N<<;
int n,m;int f[N];set<int>s[N];
IN int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
IN bool pan_n(){
set<int>::iterator it;
for(int i=;i<=n;i++)f[i]=i;
for(int i=;i<=n;i++)
for(it=s[i].begin();it!=s[i].end();it++)
if(find(i)!=find(*it))f[f[i]]=f[*it];
find();//this
int fa=f[],k=;
for(int i=;i<=n;i++){
find(i);//this
if(f[i]!=fa)return ;
if(s[i].size()&)k++;
}
if(k==)return ;return ;
}
IN void read(){
n=gi();m=gi();
for(int i=;i<=n;i++)s[i].clear();
while(m--){
int u=gi(),v=gi();
s[u].insert(v);s[v].insert(u);
}
if(pan_n())printf("Yes\n");else printf("No\n");
}
}ou;
int main()
{
freopen("42.in","r",stdin);
freopen("42.out","w",stdout);
int T=gi();
while(T--)ou.read();
return ;
}

最新文章

  1. 使用IHTMLDocument2解决弹出&quot;为了让该网站给你提供个人化信息,是否允许在你计算机放置cookie?&quot;
  2. [LintCode] Flatten Nested List Iterator 压平嵌套链表迭代器
  3. 第二课:判断js变量的类型以及domReady的原理
  4. 微信开发之——Php批量生成带参数的二维码
  5. android开发 锁屏 真正的锁屏,是go锁屏那种。
  6. JS1 js获取dom元素方法
  7. 重新认识Intent
  8. webpack安装教程及实例
  9. 兼容ie7以上的 placeholder属性
  10. Superset安装与使用
  11. dic and set
  12. LCA的两种写法
  13. 访问win10的远程桌面(Remote Desktop)总是凭据或者用户密码错误
  14. 牛客练习赛22 简单瞎搞题(bitset优化dp)
  15. springMVC一个Controller处理所有用户请求的并发问题
  16. idea本地将本地现有的项目和gitlab进行管理并提交到线上
  17. 从join on和where执行顺序认识T-SQL查询处理执行顺序
  18. css 解决父div与子div不在同一容器的问题
  19. sql server 2008数据库 降为 sql server 2005数据库 最终方案总结
  20. python实现用户登录问候

热门文章

  1. Java基本输入输出
  2. js 的静态获取和动态获取
  3. php第二十九节课
  4. LINUX-SWAP文件系统
  5. django中配置允许跨域请求
  6. airfoil polar data during post stall stages (high AOA)
  7. Codeforces 989C - A Mist of Florescence
  8. c#string类型反序列化成字典类型
  9. 【01】bootstrap基本信息
  10. 文化之旅 2012年NOIP全国联赛普及组