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 EulerianSemi-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
题⽬⼤意:如果⼀个连通图的所有结点的度都是偶数,那么它就是Eulerian,如果除了两个结点的度是
奇数其他都是偶数,那么它就是Semi-Eulerian,否则就是Non-Eulerian~
分析:⽤邻接表存储图,判断每个结点的度【也就是每个结点i的v[i].size()】是多少即可得到最终结果
~注意:图必须是连通图,所以要⽤⼀个深搜判断⼀下连通性,从结点1开始深搜,如果最后发现统计
的连通结点个数cnt != n说明是不是连通图,要输出Non-Eulerian~
 #include <iostream>
using namespace std;
int path[] = { }, graph[][];
int n, m, a, b, odd = , num = ;
bool visit[] = { false };
void DFS(int s)
{
visit[s] = true;
num++;
for (int i = ; i <= n; ++i)
if (graph[s][i] == && visit[i] == false)
DFS(i);
}
int main()
{
cin >> n >> m;
while (m--)
{
cin >> a >> b;
path[a]++;
path[b]++;
graph[a][b] = graph[b][a] = ;
}
for (int i = ; i <= n; ++i)
{
if (path[i] % == )
odd++;
cout << (i == ? "" : " ") << path[i];
}
DFS();//判断是不是连通图
if (num == n && odd == )
cout << endl << "Eulerian" << endl;
else if (num == n && odd == )
cout << endl << "Semi-Eulerian" << endl;
else
cout << endl << "Non-Eulerian" << endl;
return ;
}

PAT甲级——A1126 Eulerian Path【30】的更多相关文章

  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

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

  3. PAT甲级——1126 Eulerian Path

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

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

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

  5. PAT A1126 Eulerian Path (25 分)——连通图,入度

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

  6. A1126. Eulerian Path

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

  7. 【PAT甲级】1053 Path of Equal Weight (30 分)(DFS)

    题意: 输入三个正整数N,M,S(N<=100,M<N,S<=2^30)分别代表数的结点个数,非叶子结点个数和需要查询的值,接下来输入N个正整数(<1000)代表每个结点的权重 ...

  8. PAT 甲级 1030 Travel Plan (30 分)(dijstra,较简单,但要注意是从0到n-1)

    1030 Travel Plan (30 分)   A traveler's map gives the distances between cities along the highways, to ...

  9. PAT甲级——A1155 HeapPaths【30】

    In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...

随机推荐

  1. 每天进步一点点-深度学习入门-基于Python的理论与实现 (2)

    今天要补上两天的 不补了,新手,看的比较慢-- 手写识别例子跳过先 思考如何实现数字5的识别 三种方法: 训练数据:学习,寻找最优解 测试数据:评价模型能力. 损失函数:以损失函数为线索寻找自由权重参 ...

  2. DataWorks2.0的“业务流程”与1.0的“工作流”的对比

    DatwWorks终于升级2.0了,心情万分激动之余,又有一丝担忧.因为,没法再创建新的旧版工作流了...新版抛弃了“工作流”这个概念,引入了“业务流程”和“解决方案”两个新的概念.于是,作为团队Le ...

  3. 通过base64实现图片下载功能(基于vue)

    1. 使用场景 当我们处理图片下载功能的时候,如果本地的图片,那么是可以通过canvas获得图片的base64的,方法如下.但是如果图片的url存在跨域问题的话,下面的方法将行不通,这时候我们可以另辟 ...

  4. CF16E Fish(状压+期望dp)

    [传送门[(https://www.luogu.org/problemnew/show/CF16E) 解题思路 比较简单的状压+期望.设\(f[S]\)表示\(S\)这个状态的期望,转移时挑两条活着的 ...

  5. FFT的应用

    FFT的应用 --讲稿 概述 FFT的模板很简单,大家都会背,于是出题的空间就在于建模了.FFT的题目难在建模,往往需要将问题抽象出来,经过一系列转化后得到乘积式的和,再赋予式子各个项的系数一定的意义 ...

  6. C++学习 | C++ Implement的使用 | 消除 warning C4251 | 精简库接口

      在编写C++动态库的过程中,我们常常会听到某个要求:请隐藏动态库头文件里类接口里的成员变量!或者自己在编写动态库时,突然意识到自己好像让调用者看到的信息太多了,而这些信息根本无需被调用者看到,往往 ...

  7. day27-面向对象进阶

    #!/usr/bin/env python # -*- coding:utf-8 -*- # ----------------------------------------------------- ...

  8. Day 9 :初识函数

    Python函数:1.函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 2.函数能提高应用的模块性,和代码的重复利用率. Python提供了许多内建函数,比如print().但你也可 ...

  9. 关于JQuery Ajax 跨域 访问.net WebService

    关于这个 jQuery Ajax跨域访问 WebService 前天整了好几个小时没整明白 今天再看一下 结果突然就顿悟了 1.建一个空webApplication --添加--新建项--web服务( ...

  10. python中面向对象

    一.Python经典类与新类 经典类:如果没有直接或间接的子类化一个对象,也就是说如果没有指定一个父类,或者是如果子类化的基本类没有父类,那么就定义了经典类: class classics: 'def ...