1126. Eulerian Path (25)

时间限制
300 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They were first discussed by Leonhard Euler while solving the famous Seven
Bridges of Konigsberg problem in 1736. It has been proven that connected graphs with all vertices of even degree have an Eulerian circuit, and such graphs are called Eulerian. If there are exactly two vertices of odd degree, all Eulerian paths
start at one of them and end at the other. A graph that has an Eulerian path but not an Eulerian circuit is called semi-Eulerian. (Cited from https://en.wikipedia.org/wiki/Eulerian_path)

Given an undirected graph, you are supposed to tell if it is Eulerian, semi-Eulerian, or non-Eulerian.

Input Specification:

Each input file contains one test case. Each case starts with a line containing 2 numbers N (<= 500), and M, which are the total number of vertices, and the number of edges, respectively. Then M lines follow, each describes an edge by giving the two ends of
the edge (the vertices are numbered from 1 to N).

Output Specification:

For each test case, first print in a line the degrees of the vertices in ascending order of their indices. Then in the next line print your conclusion about the graph -- either "Eulerian", "Semi-Eulerian", or "Non-Eulerian". Note that all the numbers in the
first line must be separated by exactly 1 space, and there must be no extra space at the beginning or the end of the line.

Sample Input 1:

7 12
5 7
1 2
1 3
2 3
2 4
3 4
5 2
7 6
6 3
4 5
6 4
5 6

Sample Output 1:

2 4 4 4 4 4 2
Eulerian

Sample Input 2:

6 10
1 2
1 3
2 3
2 4
3 4
5 2
6 3
4 5
6 4
5 6

Sample Output 2:

2 4 4 4 3 3
Semi-Eulerian

Sample Input 3:

5 8
1 2
2 5
5 4
4 1
1 3
3 2
3 4
5 3

Sample Output 3:

3 3 4 3 3
Non-Eulerian
——————————————————————————————
题目的意思是给出n条边的关系,输出每个点的度和判断是欧拉回路还是欧拉路径还是什么都不是
思路:开数组保存每个点的度,先并查集找出是否是一个连通图,再找出度为奇数的点的数量没如果没有则为欧拉回路,如果是2个则为欧拉路径,否则什么都不是
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define LL long long
const int inf=0x3f3f3f3f; int cnt[10005];
int pre[10005];
void init()
{
for(int i=0; i<10005; i++)
pre[i]=i;
} int fin(int x)
{
return x==pre[x]?x:pre[x]=fin(pre[x]);
} int main()
{
int m,n,u,v;
scanf("%d%d",&m,&n);
memset(cnt,0,sizeof cnt);
init();
for(int i=0; i<n; i++)
{
scanf("%d%d",&u,&v);
int a=fin(u);
int b=fin(v);
if(a!=b)
pre[a]=b;
cnt[u]++,cnt[v]++;
}
int ans=0;
int q=0;
int flag=0;
for(int i=1; i<=m; i++)
{
if(cnt[i]%2) ans++;
if(pre[i]==i) flag++;
if(q++)
printf(" ");
printf("%d",cnt[i]);
}
printf("\n");
if(flag==1)
printf("%s\n",ans==0?"Eulerian":(ans<=2)?"Semi-Eulerian":"Non-Eulerian");
else
printf("Non-Eulerian\n");
return 0;
}

PAT甲级 1126. Eulerian Path (25)的更多相关文章

  1. PAT甲级——1126 Eulerian Path

    我是先在CSDN上发布的这篇文章:https://blog.csdn.net/weixin_44385565/article/details/89155050 1126 Eulerian Path ( ...

  2. PAT 甲级 1126 Eulerian Path

    https://pintia.cn/problem-sets/994805342720868352/problems/994805349851185152 In graph theory, an Eu ...

  3. 1126. Eulerian Path (25)

    In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similar ...

  4. PAT甲级——A1126 Eulerian Path【30】

    In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similar ...

  5. PAT甲题题解-1126. Eulerian Path (25)-欧拉回路+并查集判断图的连通性

    题目已经告诉如何判断欧拉回路了,剩下的有一点要注意,可能图本身并不连通. 所以这里用并查集来判断图的联通性. #include <iostream> #include <cstdio ...

  6. 1126 Eulerian Path (25 分)

    1126 Eulerian Path (25 分) In graph theory, an Eulerian path is a path in a graph which visits every ...

  7. PAT 1126 Eulerian Path[欧拉路][比较]

    1126 Eulerian Path (25 分) In graph theory, an Eulerian path is a path in a graph which visits every ...

  8. 【刷题-PAT】A1126 Eulerian Path (25 分)

    1126 Eulerian Path (25 分) In graph theory, an Eulerian path is a path in a graph which visits every ...

  9. PAT 1126 Eulerian Path

    In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similar ...

随机推荐

  1. Redis进阶实践之二十 Redis的配置文件使用详解

    一.引言 写完上一篇有关redis使用lua脚本的文章,就有意结束Redis这个系列的文章了,当然了,这里的结束只是我这个系列的结束,但是要学的东西还有很多.但是,好多天过去了,总是感觉好像还缺点什么 ...

  2. 【Android优化篇】提升Activity加载速度的方法

    文章转自:http://www.jianshu.com/p/2007ca0290d3 作者: CoderFan 前言 这个也是我面试遇到的问题,当时只回答了一种情况,异步加载数据,没想到别的方式,回来 ...

  3. JS 实现 jQuery的$(function(){});

    1.浏览器渲染引擎的HTML解析流程 何谓“渲染”,其实就是浏览器把请求到的HTML内容显示出来的过程.渲染引擎首先通过网络获得所请求文档的内容,通常以8K分块的方式完成.下面是渲染引擎在取得内容之后 ...

  4. java mina框架使用

    1.目前为止,看到写mina最清晰的一篇博客:https://my.oschina.net/ielts0909/blog/85946! 2.官网的开发文档:http://mina.apache.org ...

  5. python爬虫 urllib库基本使用

    以下内容均为python3.6.*代码 学习爬虫,首先有学会使用urllib库,这个库可以方便的使我们解析网页的内容,本篇讲一下它的基本用法 解析网页 #导入urllib from urllib im ...

  6. C++11与Unicode及使用标准库进行UTF-8、UTF-16、UCS2、UCS4/UTF-32编码转换

    zt https://blog.poxiao.me/p/unicode-character-encoding-conversion-in-cpp11/ Unicode Unicode是计算机领域的一项 ...

  7. linux-ubuntu 下R无法安装rjava模块的原因及解决方案

    错误信息: 没有 /usr/lib/jvm/default-java/jre/bin/java 原因: R找不到java作为依赖 解决方案: (1) 如果你没有安装java,请先安装java. (2) ...

  8. spring boot 无法启动

    spring boot 使用内置tomcat 报错  : Unable to start embedded Tomcat servlet container Tomcat connector in f ...

  9. sqlserver 数据迁移

    转载地址: 1.https://blog.csdn.net/yh_zeng2/article/details/72901892 2.https://www.cnblogs.com/jpfss/p/91 ...

  10. 《C#从现象到本质》读书笔记(二)第2章 C#类型基础(上)

    <C#从现象到本质>读书笔记第二篇 第2章 C#类型基础(上) 类型指的是集合{类,结构,接口,枚举,委托}中的任意一个成员.任何拥有某类型的值(value)称为某类型的一个实例(inst ...