首页 技术 正文
技术 2022年11月14日
0 收藏 315 点赞 2,153 浏览 954 个字

欧拉回路

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8186    Accepted Submission(s): 2926

Problem Description欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路。现给定一个图,问是否存在欧拉回路? Input测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是节点数N ( 1 < N < 1000 )和边数M;随后的M行对应M条边,每行给出一对正整数,分别是该条边直接连通的两个节点的编号(节点从1到N编号)。当N为0时输入结 束。 Output每个测试用例的输出占一行,若欧拉回路存在则输出1,否则输出0。 Sample Input3 31 21 32 33 21 22 30 Sample Output10

简单的欧拉回路判断,欧拉回路入门:

 #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
using namespace std;
#define ll long long int
int a[];
int find(int x)
{
if(a[x]!=x)
a[x]=find(a[x]);
return a[x];
}
int main()
{
int n,m;
while(cin>>n,n)
{
cin>>m;
int i,x,y;
int b[n+];
a[]=;
for(i=;i<=n;i++)
a[i]=i;
memset(b,,sizeof(b));
for(i=;i<m;i++)
{
scanf("%d%d",&x,&y);
b[x]++;
b[y]++;
if(y<x)
swap(x,y);
int fx=find(x);
int fy=find(y);
if(fy!=fx)
a[fy]=fx;
}
int sum=;
for(i=;i<=n;i++)
{
if(b[i]%==&&a[i]==)
sum++;
}
if(sum==n)
cout<<<<endl;
else cout<<<<endl;
} }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,033
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,862