K - 欧拉回路(并查集)
束。
3 3
1 2
1 3
2 3
3 2
1 2
2 3
0
1
0
a、b ,a 的入度比 b 的入度大 1,a 的出度比 b 小 1
Select Code
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std; int count=0;
int par[10000];
int aa[1005];
void init(int a)
{
for(int i=1; i<=a; i++)
par[i]=i;
} int find(int x)
{
if(x==par[x])
return x;
else
return par[x]=find(par[x]);
} void join(int x, int y)
{
int count=0;
int fx=find(x),fy=find(y);
if(fx!=fy)
{
par[fx]=fy;
}
}
int main()
{
int count;
int a,b;
while(~scanf("%d%d",&a,&b)&&a)
{
init(a);
int flag=1;
memset(aa, 0, sizeof(aa)); //清空数组
for(int i=1; i<=b; i++)
{
int x,y;
scanf("%d%d",&x,&y);
aa[x]++ , aa[y]++; //记录节点的入度和出度
join(x,y);
}
int sum=0;
for(int i=0; i<a; i++)
{
if(par[i]==i)
sum++;
if(aa[i]&1) //aa[i]%2flag=0;}
if(sum!=1)
flag = 0;
printf("%d\n",flag);
}
return 0;
}
还可以用dfs来做;
K - 欧拉回路(并查集)的更多相关文章
- POJ 2513 Colored Sticks (欧拉回路+并查集+字典树)
题目链接 Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with ...
- HDU 1116 Play on Words(欧拉回路+并查集)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1116 Play on Words Time Limit: 10000/5000 MS (Java/Ot ...
- HDU1878 欧拉回路---(并查集+图论性质)
http://acm.hdu.edu.cn/showproblem.php?pid=1878 欧拉回路 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU-1878 欧拉回路(并查集,欧拉回路性质)
欧拉回路 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- ACM: FZU 2112 Tickets - 欧拉回路 - 并查集
FZU 2112 Tickets Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u P ...
- hdu 3018 Ant Trip 欧拉回路+并查集
Ant Trip Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...
- HDU 1116 || POJ 1386 || ZOJ 2016 Play on Words (欧拉回路+并查集)
题目链接 题意 : 有很多门,每个门上有很多磁盘,每个盘上一个单词,必须重新排列磁盘使得每个单词的第一个字母与前一个单词的最后一个字母相同.给你一组单词问能不能排成上述形式. 思路 :把每个单词看成有 ...
- POJ2513——Colored Sticks(Trie树+欧拉回路+并查集)
Colored Sticks DescriptionYou are given a bunch of wooden sticks. Each endpoint of each stick is col ...
- nyist 42 一笔画 (欧拉回路 + 并查集)
nyoj42 分析: 若图G中存在这样一条路径,使得它恰通过G中每条边一次,则称该路径为欧拉路径. 若该路径是一个圈,则称为欧拉(Euler)回路. 具有欧拉回路的图称为欧拉图(简称E图).具有欧拉路 ...
随机推荐
- c# 数据集调试工具插件
DataSetSpySetup,调试期查看dataset数据集的记录内容, Debug DataSet
- IBM X3650 M4 主板故障
故障描述: 今天突然接到报警,一台服务器无法连通,无法登录.无法 ping 通. 打电话到 IDC ,授权工程师查看服务器状态,返回结果如下: 1.服务器关机状态 2.无法开机 ( 电源灯亮 ),按开 ...
- Hive的安装和建表
目录 认识Hive 1. 解压 2. 配置mysql metastore(切换到root用户) 3. 配置hive 4. 安装hive和mysq完成后,将MySQL的连接jar包拷贝到$HIVE_HO ...
- Jmeter Http接口性能测试
Jmeter Http接口性能测试 1. 启动Jmeter Jmeter下载解压即可使用,Jmeter启动,点击D:\ProgramFiles\jmeter\apache-jmeter-2. ...
- Solr Dismax查询解析器-深入分析
Solr 支持多种查询解析,给搜索引擎开发人员提供灵活的查询解析.Solr 中主要包含这几个查询解析器:标准查询解析器.DisMax 查询解析器,扩展 DisMax 查询解析器(eDisMax) Di ...
- 关于ueditor使用说明
1.后台配置文件config.json中的各种prefix,相对的都是网站(发布后的)的根目录, 2.需要在iis下将net文件夹转换为应用程序 3.<div> <h1> ...
- for 续2
--------siwuxie095 (二)skip=n 忽略(屏蔽.隐藏)文本前 N 行的内容. (N 必须大于 0,不能等于 0) 格式: FOR /F " ...
- 22-python爬虫解决gbk乱码问题
转载自: python爬虫解决gbk乱码问题 今天尝试了下爬虫,爬取一本小说,忘语的凡人修仙仙界篇,当然这样不好,大家要支持正版. 爬取过程中是老套路,先获取网页源代码 # -*- coding: ...
- Rotate image and fit show use canvas
Description In the field of image processing, We always to show image after modified the image raw d ...
- zookeeper的ZAB协议
ZAB协议概述 ZooKeeper并没有完全采用Paxos算法,而是使用了一种称为ZooKeeper Atomic Broadcast(ZAB,zookeeper原子消息广播协议)的协议作为其数据一致 ...