【NYOJ42】一笔画问题
2016-10-05 13:42
393 查看
[b]一笔画问题[/b]
时间限制: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=100010; const int MAXM=100010; 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=0,q=0;register char ch=getchar(); while((ch<'0'||ch>'9')&&ch!='-')ch=getchar(); if(ch=='-')q=1,ch=getchar(); while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar(); return q?-w:w; } struct Fleury{ static const int N=1010,M=N<<2; int n,m;int f ;set<int>s ; 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=1;i<=n;i++)f[i]=i; for(int i=1;i<=n;i++) for(it=s[i].begin();it!=s[i].end();it++) if(find(i)!=find(*it))f[f[i]]=f[*it]; find(1);//this int fa=f[1],k=0; for(int i=1;i<=n;i++){ find(i);//this if(f[i]!=fa)return 0; if(s[i].size()&1)k++; } if(k==2)return 1;return 0; } IN void read(){ n=gi();m=gi(); for(int i=1;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 0; }
相关文章推荐
- NYOJ-42 一笔画问题
- nyoj_42 一笔画问题
- NYOJ42 一笔画问题 欧拉回路判定+前向星
- NYOJ-42 一笔画问题(图论,深搜)
- NYOJ42-一笔画问题
- NYOJ 42 一笔画问题
- nyoj,42,一笔画问题
- NYOJ 42-一笔画问题:欧拉路径
- nyoj 42-一笔画问题
- NYOJ 42 一笔画问题 http://acm.nyist.net/JudgeOnline/problem.php?pid=42
- NYOJ 42 一笔画问题
- NYOJ42 一笔画问题
- NYOJ42 一笔画问题
- 欧拉路/回路_并查集 NYOJ 42 一笔画问题
- NYOJ 42 一笔画问题
- NYOJ-42 一笔画问题
- NYOJ42 一笔画问题
- NYOJ42-一笔画问题
- NYOJ 题目42 一笔画问题(欧拉路,图的连通性)
- Nyoj 42 一笔画问题