HDU1878 欧拉回路 - from lanshui_Yang
束。
1 2
1 3
2 3
3 2
1 2
2 3
0
0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<queue>
using namespace std ;
const int MAXN = 1005 ;
int set[MAXN] ;
int d[MAXN] ; // 存顶点的度
inline void RD (int &a) // 输入优化
{
a = 0 ;
char t ;
while ((t = getchar()) && t >= '0' && t <= '9')
{
a = a * 10 + t - '0' ;
}
}
int find(int x) // 并查集
{
int r = x ;
while ( r != set[r] )
{
r = set[r] ;
}
return r ;
}
int main()
{
int n , m ;
while (1)
{
RD(n) ;
if(n == 0)
break ;
memset(set , 0 , sizeof(set)) ;
memset(d , 0 , sizeof(d)) ;
RD(m) ;
int i ;
for(i = 1 ; i <= n ; i ++) // 初始化并查集
{
set[i] = i ;
}
for(i = 0 ; i < m ; i ++)
{
int a , b ;
RD(a) ;
RD(b) ;
d[a] ++ ;
d[b] ++ ;
int ta , tb ;
ta = find(a) ;
tb = find(b) ;
if(ta < tb)
{
set[tb] = ta ;
}
else
set[ta] = tb ;
}
int sumj = 0 ;
int fz = 0 ;
for(i = 1 ; i <= n ; i ++)
{
if(set[i] == i)
{
fz ++ ;
}
if(d[i] % 2 == 1)
{
sumj ++ ;
}
}
if(fz > 1 || sumj > 0)
{
printf("0\n") ;
}
else
{
printf("1\n") ;
}
}
return 0 ;
}
HDU1878 欧拉回路 - from lanshui_Yang的更多相关文章
- HDU-1878 欧拉回路 欧拉回路
题目链接:https://cn.vjudge.net/problem/HDU-1878 题意 中文题,而且就是单纯的欧拉回路 思路 判断连通图 用并查集会很好,bfs亦可 一时脑抽用bfs过了这个题, ...
- hdu1878 欧拉回路
//Accepted 1240 KB 250 ms //水题 欧拉回路 //连通+节点度均为偶数 #include <cstdio> #include <cstring> #i ...
- HDU1878 欧拉回路---(并查集+图论性质)
http://acm.hdu.edu.cn/showproblem.php?pid=1878 欧拉回路 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- 欧拉回路基础 HDU1878 欧拉回路||并差集
欢迎参加——每周六晚的BestCoder(有米!) 欧拉回路 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- hdu1878欧拉回路(DFS+欧拉回路)
欧拉回路 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDU-1878 欧拉回路(并查集,欧拉回路性质)
欧拉回路 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- HDU1878欧拉回路
这道题WA了好多次.测试数据感觉有点问题-- 并查集啊,必须有. #include<stdio.h> #include<string.h> int ad[1003]; int ...
- 欧拉图Eulerian Graph
一.节点的度 无向图:节点的度为该节点所连接的边数 有向图:节点的度分为入度和出度. 二.欧拉图定义 具有欧拉回路的图称作欧拉图,具有欧拉路径而无欧拉回路的图称为半欧拉图. 欧拉回路: 通过图中每 ...
- hdu1878判断欧拉回路
欧拉回路 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
随机推荐
- HDU 1849 Rabbit and Grass
题解:因为棋子可重叠,所以就等于取石子问题,即尼姆博弈,SG[i]=i,直接将输入数据异或即可. #include <cstdio> int main(){ int SG,n,a; whi ...
- HDU 2178 猜数字
题解:设猜到的最大的数是h,在1到h间,你最多只要猜log2(h)+1(取整)次,所以易知==>h=2^m-1.即猜m次,能猜到的最大的数为2^m-1. #include <cstdio& ...
- 中国天气网API
中国天气网有三个 API 适用于不同场合的使用. http://m.weather.com.cn/data/101050101.html 这个接口返回的格式如下. { "weatherinf ...
- CTreeCtrl 控件使用总结
一 基础操作 1 插入节点 1)插入根节点 [cpp] view plaincopy //插入根节点 HTREEITEM hRoot; CString str=L"ROOT" h ...
- Why is celsius = 5 * (fahr - 32) / 9 ?
Go to my personal blog There is a program to print Fahrenheit-Celsius table as below. #include <s ...
- 你应当知道的Java牛人
Java领域有非常多著名的人物,他们为Java社区编写框架.产品.工具或撰写书籍改变了Java编程的方式. 本文是<最受欢迎的8位Java牛人>的2.0版本号. PS:排名不分先后.本文的 ...
- Port 8081 already in use, packager is either not running or not running correctly
运行 react_native 时发生这个错误,解决办法 关掉端口8081对应的进程 1.打开终端,输入命令:lsof -i:8081 2.此时提示: COMMAND PID USER ...
- commons-logging \ log4j \ slf4j 之间的关系
最近的一个web项目中要使用到日志,但是对常用的日志记录工具(框架)着实不是很理解,在此mark一下. 1.commons-logging.jar common-logging是apache提供的一个 ...
- Iframe知识点
var oIframe=document.getElementById('iframe1'); 获取iframe对象: oIframe.contentWindow.// iframe 里的win ...
- KbmMW两种查询结果集通讯方式
KbmMW本身可以用QueryService的方式进行远程数据查询,但是SmpileService同样具有很强的扩展性可以实现数据查询,下面展示两种基于SmpileService的远程数据查询方法,其 ...