0 0 Yes

1 1 0 0 Yes

1 2 2 1 0 0 No

//自回路不算一条边的! 居然有 0 0 这样的测试数据

#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
set<int> ans;
set<int> member;
const int SIZE=+;
int par[SIZE];
int rnk[SIZE];
void init(int n)
{
for(int i=; i<=n; i++)
{
par[i]=i;
rnk[i]=;
}
} int fnd(int x)
{
if(par[x]==x)
return x;
return par[x]=fnd(par[x]);
} void unite(int x, int y)
{
int a=fnd(x);
int b=fnd(y); if(a==b)
return ;
if(rnk[a]<rnk[b])
{
par[a]=b;
}
else
{
par[b]=a;
if(rnk[a]==rnk[b])
rnk[a]++;
}
} int main()
{ int x,y;
int cnt=;
init(SIZE-);
int flag=;
while(scanf("%d %d",&x, &y)!=EOF&&x!=-&&y!=-)
{
if(x==&&y==)
{
if(flag==)
{
printf("Yes\n");
continue;
} if(member.size()!=cnt+)
{
printf("No\n");
}
else
{ for(set<int>:: iterator it=member.begin(); it!=member.end(); it++)
{
ans.insert(fnd(*it));
}
if(ans.size()==)
printf("Yes\n");
else
printf("No\n");
} member.clear();
ans.clear();
cnt=;
init(SIZE-);
flag=;
}
else
{
flag=;
unite(x,y);
member.insert(x);
member.insert(y);
if(x!=y)
{
cnt++;
}
} } return ;
}

最新文章

  1. ios常用的第三方库
  2. jQuery用户数字评分效果
  3. 深入理解javascript函数系列第一篇——函数概述
  4. Jquery-pagination.js分页处理
  5. 万恶的ViewBag
  6. 读《深入理解Java虚拟机》有感——第一部分:Class文件的结构
  7. 利用Splatting提交参数(Hash,哈希)
  8. Dedecms自定义sql 出现错误Safe Alert: Request Error step 2!
  9. [Android学习笔记]子线程更新UI线程方法之Handler
  10. Ubuntu 16.04 samba相关配置
  11. 集合框架(HashSet存储自定义对象保证元素唯一性)
  12. year:2017 month:8 day:3
  13. Vuex 教程案例:计数器以及列表展示
  14. 使用TortoiseSVN打Tag
  15. Android ios嵌套web页面
  16. c/c++连通图的遍历(深度遍历/广度遍历)
  17. Java面试MySQL的一些问题
  18. 基于Redis的INCR实现一个限流器
  19. (零 ) 天猫精灵接入Home Assistant-总说明
  20. MySQL垂直拆分和水平拆分的优缺点和共同点总结

热门文章

  1. vue项目创建流程和使用
  2. host更新
  3. C# 汉字编码GB2312转换
  4. LeetCode:快乐数【202】
  5. linux中添加PHP的mongoDB支持扩展
  6. Data Structure Array: Find the minimum distance between two numbers
  7. iOS项目中获取验证码倒计时及闪烁问题解决方案
  8. python3 mysql 多表查询
  9. 一看就懂的数据库范式介绍(1NF,2NF,3NF,BC NF,4NF,5NF)
  10. mysql备份,知识点