NYIST OJ 题目42 一笔画问题
水题。无向图欧拉通路的判定。用并查集判定是不是连通图!
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn = + ;
int tott[maxn];
int father[maxn]; int find(int x)
{
if (x != father[x]) father[x] = find(father[x]);
return father[x];
} int main()
{
int T;
scanf("%d", &T);
while (T--)
{
int i, n, m, u, v;
scanf("%d%d", &n, &m);
for (i = ; i <= n; i++) father[i] = i;
memset(tott, , sizeof(tott));
for (i = ; i < m; i++)
{
scanf("%d%d", &u, &v);
int fu = find(u);
int fv = find(v);
if (fu != fv) father[fu] = fv;
tott[u]++;
tott[v]++;
}
int ji = , ou = ;
for (i = ; i <= n; i++)
{
if (tott[i] == ) continue;
if (tott[i] % == ) ou++;
else ji++;
}
int jieguo = ;
int th = find();
for (i = ; i <= n; i++)
{
int tg = find(i);
if (tg != th) break;
}
if (i == n + ) jieguo = ;
if (jieguo == )
{
if (ji == || ji == ) jieguo = ;
else jieguo = ;
}
if (jieguo == ) printf("Yes\n");
else printf("No\n");
}
return ;
}
NYIST OJ 题目42 一笔画问题的更多相关文章
- NYOJ 题目42 一笔画问题
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...
- NYOJ 题目42 一笔画问题(欧拉图)
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描写叙述 zyc从小就比較喜欢玩一些小游戏.当中就包含画一笔画.他想请你帮他写一个程序.推断一个图是否可以用一笔画下 ...
- NYIST OJ 题目38 布线问题
最小生成树水题,先按最小生成树做,答案最后加上最小的从第i号楼接线到外界供电设施所需要的费用即可. #include<cstdio> #include<cstring> #in ...
- NYIST OJ 题目20 吝啬的王国
DFS水题.题意说明了这是一颗树,那么只要按照根节点DFS下去就好了,DFS的时候记录一下当前在哪个结点,还有父节点是谁,就AC了! #include<cstdio> #include&l ...
- nyoj 42 一笔画 欧拉通路
http://acm.nyist.net/JudgeOnline/problem.php?pid=42 一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc ...
- 九度oj 题目1007:奥运排序问题
九度oj 题目1007:奥运排序问题 恢复 题目描述: 按要求,给国家进行排名. 输入: 有多组数据. 第一行给出国家数N,要求排名的国家数M,国家号 ...
- 九度OJ 题目1384:二维数组中的查找
/********************************* * 日期:2013-10-11 * 作者:SJF0115 * 题号: 九度OJ 题目1384:二维数组中的查找 * 来源:http ...
- hdu 1284 关于钱币兑换的一系列问题 九度oj 题目1408:吃豆机器人
钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- 刘汝佳黑书 pku等oj题目
原文地址:刘汝佳黑书 pku等oj题目[转]作者:小博博Mr 一.动态规划参考资料:刘汝佳<算法艺术与信息学竞赛><算法导论> 推荐题目:http://acm.pku.edu. ...
随机推荐
- [ios]iphone 获取UIWebView内Html方法
原文:http://blog.csdn.net/diyagoanyhacker/article/details/6564897 获取所有html:NSString *lJs = @"docu ...
- Oracle-11g 中两库间物化视图的同步
html,body { font-size: 15px } body { font-family: Helvetica, "Hiragino Sans GB", "微软雅 ...
- 五、RDD持久化
Spark最重要的一个功能是它可以通过各种操作(operations)持久化(或者缓存)一个集合到内存中.当你持久化一个RDD的时候,每一个节点都将参与计算的所有分区数据存储到内存中,并且这些数据可以 ...
- sql的ExecuteScalar(),ExecuteNonQuery()
一,ExecuteScalar ExecuteScalar()也返回一个int型变量.如果SQL语句是Select查询,则仅仅返回查询结果集中第一行第一列,而忽略其他行和列.如果SQL语句不是Sele ...
- Haskell Seq函数和严格计算
参考链接http://stackoverflow.com/questions/11046590/the-seq-function-and-strictness https://wiki.haskell ...
- C# SessionHelper
using System.Web; using System.Web.SessionState; namespace Utils { /// <summary> /// Session帮助 ...
- Leetcode easy
1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...
- 关于eclipse中代码与SVN服务器关联问题
今天开始开发新项目,此项目采用maven搭建,分多个工程,用eclipse的SVN插件检出工程之后只有一个工程,只好用桌面端的SVN工具检出,然后再import导入到eclipse中直接变成了多个工程 ...
- 字符串---分割成数组(str_split ),算出一个字符串中出现最多的字符, 学校中最多的姓名
split 分割separate分开 little 小的 echo '<meta http-equiv="Content-type" content="text/h ...
- 启动Mysql报错:Another MySQL daemon already running with the same unix socket.
启动Mysql报错: Another MySQL daemon already running with the same unix socket. 删除如下文件即可解决 /var/lib/mysql ...