【NYOJ42】一笔画问题
一笔画问题
Position:http://acm.nyist.net/JudgeOnline/problem.php?pid=42
Description
规定,所有的边都只能画一次,不能重复画。
Input
第一行只有一个正整数N(N<=10)表示测试数据的组数。
每组测试数据的第一行有两个正整数P,Q(P<=1000,Q<=2000),分别表示这个画中有多少个顶点和多少条连线。(点的编号从1到P)
随后的Q行,每行有两个正整数A,B(0<A,B<P),表示编号为A和B的两点之间有连线。
Output
如果不存在符合条件的连线,输出"No"。
2
4 3
1 2
1 3
1 4
4 5
1 2
2 3
1 3
1 4
3 4
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 ;
}
【NYOJ42】一笔画问题的更多相关文章
- nyoj-----42一笔画问题
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...
- Nyoj42 一笔画问题 (欧拉道路)
http://acm.nyist.net/JudgeOnline/problem.php?pid=42题目链接 #include <cstdio> #include <cstring ...
- nyoj42一笔画问题(欧拉图)
这题事实上说不上难度4.仅仅是一个简单的欧拉图推断,给一些点,首先推断连通性.假设不连通.就谈不上是欧拉图. 假设是连通的,在推断度的数目,每一个顶点都是偶数个或者仅仅有两个是奇数个.这样就能够构成欧 ...
- nyist 42 一笔画 (欧拉回路 + 并查集)
nyoj42 分析: 若图G中存在这样一条路径,使得它恰通过G中每条边一次,则称该路径为欧拉路径. 若该路径是一个圈,则称为欧拉(Euler)回路. 具有欧拉回路的图称为欧拉图(简称E图).具有欧拉路 ...
- nyoj-一笔画问题-欧拉图+联通判定
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...
- fcitx 候选词出现奇怪的笔画
原来fcitx还有笔画输入的功能,输入h出现一个横,s出现竖,p是撇,n是捺,z是折. 虽然很有意思,但是不实用,而且还会出现在第一页候选词中,影响输入,可以通过配置文件禁用掉: $ vim ~/.c ...
- NYOJ 42 一笔画问题
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...
- ACM题目————一笔画问题
描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来. 规定,所有的边都只能画一次,不能重复画. 输入 第一行只有一个正整数N(N< ...
- UVA 291 The House Of Santa Claus (DFS求一笔画)
题意:从左下方1开始,一笔画出圣诞老人的屋子(不过话说,圣诞老人的屋子是这样的吗?这算是个屋子么),输出所有可以的路径. 思路:贴代码. #include <iostream> #incl ...
随机推荐
- 解决vue项目运行过程中,npm run dev 报错问题
[方案1] 错误如下: npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! travel@1.0.0 dev: `webpack-dev-server ...
- IOS上MediaPlayer framework实现视频播放
播放电影文件: iOS sdk中可以使用MPMoviePlayerController来播放电影文件.但是在iOS设备上播放电影文件有严格的格式要求,只能播放下面两个格式的电影文件. • H.264 ...
- LeetCode_16 3SumCloest
3Sum Closest Given an array nums of n integers and an integer target, find three integers in nums su ...
- Linux下查看Tomcat运行日志
查看方式 1.先切换到:cd usr/local/tomcat5/logs2.tail -f catalina.out3.Ctrl+c 是退出tail命令/alt+E+R重置 部署常用指令 1.ps ...
- python_ 学习笔记(基本数据类型)
python3有6中标准数据类型:Number(数字).String(字符串).List(列表).Tuple(元组).Dictionary(字典).Set(集合)不可变数据:Number.String ...
- ORM优化
orm优化数据库访问:https://docs.djangoproject.com/en/1.11/topics/db/optimization/ 一.QuerySet 可迭代 querysey=mo ...
- PAT 1146 Topological Order
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
- [spoj1182][Sorted Bit Sequence] (数位dp)
Description Let's consider the 32 bit representation of all integers i from m up to n inclusive (m ≤ ...
- springcloud(八):熔断器Hystrix
熔断器 雪崩效应 在微服务架构中通常会有多个服务层调用,基础服务的故障可能会导致级联故障,进而造成整个系统不可用的情况,这种现象被称为服务雪崩效应.服务雪崩效应是一种因“服务提供者”的不可用导致“服务 ...
- POJ 1226 Substrings
Substrings Time Limit: 1000ms Memory Limit: 10000KB This problem will be judged on PKU. Original ID: ...