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. 惠普服务器DL360G6安装ESXi主机后遗忘密码用u盘重置密码

    惠普服务器DL360G6安装ESXi主机后遗忘密码重置密码 先用rufus制作U盘启动盘,启动盘一定要用惠普专用hpe的esxi版本,否则安装会报错, 下载https://www.iplaysoft. ...

  2. java jar 服务自启动存在的坑及解决办法

    为了在服务器重启的时候,java程序能够自动重启,我们通常把它加到服务里面 ln -s /full/path/to/jar /etc/init.d/service_name # start servi ...

  3. 516D Drazil and Morning Exercise

    分析 求出直径和最远距离d 之后我们以直径中点为根 发现父亲的d肯定不小于儿子的d 于是从下往上启发式合并维护与子树根的值相差L内的个数即可 代码 #include<bits/stdc++.h& ...

  4. fiddler之编辑请求(composer)-发包

    在需要针对接口进行发包操作时,可以使用composer标签,去编辑请求内容,进行请求. 界面显示如下: 1.Parsed 在该分页中,选择请求方法.设置请求地址和协议版本,上部分为请求的头信息.下半部 ...

  5. JVM参数配置及内存调优

    一.JVM常见参数配置 堆内存相关参数 参数名称 含义 默认值   -Xms 初始堆大小 物理内存的1/64(<1GB) 默认(MinHeapFreeRatio参数可以调整)空余堆内存小于40% ...

  6. Jmeter测试HTTP接口

    一.工具说明 Jmeter是一款开源的桌面应用软件,可以用于进行接口测试和性能测试.因为该软件是开源的,所以更具扩展性.Jmeter可以对Web应用进行测试,另外还支持Java请求.Webservic ...

  7. vs2010发布网站时有些文件没有发布出去的解决办法。

    项目中包含了一些ttf字体文件做为图标使用,可是发布时发现生成的目录中没有这个文件,这种情况这么设置一下就可以解决: 1,在文件上点击右键,选择“属性”. 2,在弹出的属性窗口中,更改“生成操作”为“ ...

  8. Burp Suite批量网页操作

    1.打开md5解密网站,并输入“21232F297A57A5A743894A0E4A801FC3”,不要点击[Decrypt It!] 1.启动Burp Suite,并设置浏览器代理 3.点击[Dec ...

  9. git自动上传脚本及基本代码

    git_auto.bat git add . git add -A git add -u git commit -m "text" git pull --rebase origin ...

  10. BZOJ 3810 [Coci2015]Stanovi

    这讲真就是一篇显得自己认真做题的博客 因为真的比较习惯将培训所有的题都放到一篇博客中,又因为暑假好多培训,所以单题很少,这也是从博客中摘出来的 题目链接 如果合法,一定有一条贯穿整个矩形的线: dp[ ...