【NYOJ42】一笔画问题
2024-08-31 00:01:29
一笔画问题
时间限制: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"。
如果不存在符合条件的连线,输出"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 ;
}
最新文章
- 使用IHTMLDocument2解决弹出";为了让该网站给你提供个人化信息,是否允许在你计算机放置cookie?";
- [LintCode] Flatten Nested List Iterator 压平嵌套链表迭代器
- 第二课:判断js变量的类型以及domReady的原理
- 微信开发之——Php批量生成带参数的二维码
- android开发 锁屏 真正的锁屏,是go锁屏那种。
- JS1 js获取dom元素方法
- 重新认识Intent
- webpack安装教程及实例
- 兼容ie7以上的 placeholder属性
- Superset安装与使用
- dic and set
- LCA的两种写法
- 访问win10的远程桌面(Remote Desktop)总是凭据或者用户密码错误
- 牛客练习赛22 简单瞎搞题(bitset优化dp)
- springMVC一个Controller处理所有用户请求的并发问题
- idea本地将本地现有的项目和gitlab进行管理并提交到线上
- 从join on和where执行顺序认识T-SQL查询处理执行顺序
- css 解决父div与子div不在同一容器的问题
- sql server 2008数据库 降为 sql server 2005数据库 最终方案总结
- python实现用户登录问候