Hrbust1658一笔画
来源:互联网 发布:mac照片占用空间 编辑:程序博客网 时间:2024/06/02 14:57
2
4 3
1 2
1 3
1 4
4 5
1 2
2 3
1 3
1 4
3 4
Sample OutputNo
Yes
很裸的欧拉图问题 ,题解在代码中
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <algorithm>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mem(a) memset(a, 0, sizeof(a))
#define eps 1e-5
#define M 100005
#define INF 0x3f3f3f3f
using namespace std;
//无向的欧拉图或者半欧拉图。 欧拉图:所有点的度为偶数。半欧拉图,起点和终点的度为奇数。
int a,b,aa,bb;
int f[M];
int pre[M];
int find(int x)
{
int r=x;
while(r!=pre[r])
{
r=pre[r];
}
return r;
}
int mx(int x,int y)
{
int xx=find(x);
int yy=find(y);
if(xx!=yy)
{
pre[xx]=yy;
}
}
int main()
{
int t;
cin>>t;
while(t--)
{
mem(f);
mem(pre);
cin>>a>>b;
for(int i=1;i<=a;i++)
{
pre[i]=i;
}
for(int i=0;i<b;i++)
{
cin>>aa>>bb;
f[aa]++;
f[bb]++;
mx(aa,bb);
}
int flag=0;
for(int i=1;i<=a;i++)
{
if(pre[i]==i)
{
flag++;
}
}
if(flag!=1)//前提:图连通
cout<<"No"<<endl;
else
{
int sum=0;
for(int i=1;i<=a;i++)
{
if(f[i]%2==1)
{
sum++;
}
}
if(sum==0||sum==2)
{
cout<<"Yes"<<endl;
}
else
cout<<"No"<<endl;
}
}
}
- Hrbust1658一笔画
- 一笔画
- 一笔画趣题
- 一笔画问题
- 一笔画问题
- 一笔画问题
- nyoj_42 一笔画问题
- NYOJ42 一笔画问题
- NYOJ42-一笔画问题
- NYOJ 一笔画问题
- 一笔画问题 nyist42
- nyoj42(一笔画)
- nyoj42一笔画问题
- 一笔画问题
- 一笔画问题
- nyoj42 一笔画问题
- 一笔画问题
- NYOJ42-一笔画问题
- OpenCV3.1.0 + contrib编译
- 面试大全3
- 第五周项目3——(1)时间类
- Java设计模式 -- 适配器模式
- C/C++中指针、引用、数组、链表的区别
- Hrbust1658一笔画
- 星号图
- HDU 2063 过山车 (二分匹配 -匈牙利算法)
- hdu 1695 莫比乌斯反演
- uva10128(Queue)
- Leetcode 47. Permutations II
- pat乙级总结
- Centos下本地连接postgresql时出现认证错误的问题
- 鼠标移入/移出改变图片透明度_jQuery效果