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
并查集判断是否连通。然后判断是不是欧拉回路或者欧拉通路。欧拉回路是所有点的度数都是偶数,欧拉通路有两个点的度数是奇数。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,v[],a,b,odd,pic;
int f[];
int getf(int x)
{
if(x != f[x])f[x] = getf(f[x]);
return f[x];
}
void mer(int x,int y)
{
int xx = getf(x);
int yy = getf(y);
f[xx] = yy;
}
void init()
{
for(int i = ;i <= n;i ++)
f[i] = i;
}
int main()
{
cin>>n>>m;
init();
for(int i = ;i < m;i ++)
{
cin>>a>>b;
mer(a,b);
v[a] ++;
v[b] ++;
}
for(int i = ;i <= n;i ++)
{
if(f[i] == i)pic ++;
if(i != n)cout<<v[i]<<' ';
else cout<<v[i]<<endl;
if(v[i] % )odd ++;
}
if(pic == && odd == )cout<<"Semi-Eulerian";
else if(pic == && odd == )cout<<"Eulerian";
else cout<<"Non-Eulerian";
}

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

  1. PAT甲级 1126. Eulerian Path (25)

    1126. Eulerian Path (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue In grap ...

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

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

  3. 1126 Eulerian Path (25 分)

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

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

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

  5. PAT甲级——1126 Eulerian Path

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

  6. PAT 甲级 1126 Eulerian Path

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

  7. PAT 1126 Eulerian Path

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

  8. 1126 Eulerian Path

    题意:若图是连通图,且所有结点的度均为偶数,则称为Eulerian:若有且仅有两个结点的度为奇数,则称为semi-Eulerian.现给出一个图,要我们判断其是否为Eulerian,semi-Eule ...

  9. PTA 1126 Eulerian Path

    无向连通图,输出每个顶点的度并判断Eulerian.Semi-Eulerian和Non-Eulerian这3种情况,我们直接记录每个点所连接的点,这样直接得到它的度,然后利用深度优先和visit数组来 ...

随机推荐

  1. C# WinForm开发系列学习 地址 很详细

    http://www.cnblogs.com/peterzb/archive/2009/07/27/1531910.html

  2. 阶段3 1.Mybatis_06.使用Mybatis完成DAO层的开发_1 Mybatis中编写dao实现类的使用方式-查询列表

    就是自己写实现类的方式来开发 直接finish 把之前写的CRUD的代码复制到过来. 在把之前pom.xml里面的包的依赖也复制过来 复制到当前的pom.xml内 允许自动导入 以上步骤就是复制了一个 ...

  3. proteus 与 keil 的安装及联调

    proteus 安装 Win10 系统的下载链接可以参考这里:https://tieba.baidu.com/p/5644915130?traceid= 百度网盘地址 链接1: http://pan. ...

  4. 递归算法之排列组合-求一个集合S的m个元素的组合和所有可能的组合情况

    求一个集合S的m个元素组合的所有情况,并打印出来,非常适合采用递归的思路进行求解.因为集合的公式,本身就是递归推导的: C(n,m) = C(n-1,m-1) + C(n-1,m). 根据该公式,每次 ...

  5. 4.站点克隆wget----隐写术图片----backbox linux

    站点克隆wget sudo bash cd Desktop/Cloned wget -h clear wget -mk https://help.ubuntu.com/ 隐写术图片 想想朋友圈的图片 ...

  6. [LeetCode] 1092. Shortest Common Supersequence

    LeetCode刷题记录 传送门 Description Given two strings str1 and str2, return the shortest string that has bo ...

  7. Canvas入门06-线段与像素边界

    我们知道,使用以下2个API可以绘制一条线段: moveTo(x, y) 向当前路径中增加一条子路径,该子路径只包含一个点,此为线段的起始点 lineTo(x, y) 将线段的下一个点加入子路径中 c ...

  8. Springboot2.x集成Redis集群模式

    Springboot2.x集成Redis集群模式 说明 Redis集群模式是Redis高可用方案的一种实现方式,通过集群模式可以实现Redis数据多处存储,以及自动的故障转移.如果想了解更多集群模式的 ...

  9. Ubuntu 16.04简单配置备忘录

    1.几个安装包的地址 1.Linux QQ:https://im.qq.com/linuxqq/index.html 2.网易云音乐:http://s1.music.126.net/download/ ...

  10. 数据分析 - 缺失值、异常值、一致性分析方法及Python实现

    1.数据质量分析 数据质量分析主要任务:检查原始数据是否存在脏数据. 脏数据: 缺失值 异常值 不一致的值 重复数据及含有特殊符号(如:#.¥.*)的数据 1.1 缺失值分析 数据缺失主要包括:记录的 ...