PAT甲级——A1126 Eulerian Path【30】
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>
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】的更多相关文章
- PAT甲级 1126. Eulerian Path (25)
1126. Eulerian Path (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue In grap ...
- PAT 甲级 1126 Eulerian Path
https://pintia.cn/problem-sets/994805342720868352/problems/994805349851185152 In graph theory, an Eu ...
- PAT甲级——1126 Eulerian Path
我是先在CSDN上发布的这篇文章:https://blog.csdn.net/weixin_44385565/article/details/89155050 1126 Eulerian Path ( ...
- 【刷题-PAT】A1126 Eulerian Path (25 分)
1126 Eulerian Path (25 分) In graph theory, an Eulerian path is a path in a graph which visits every ...
- PAT A1126 Eulerian Path (25 分)——连通图,入度
In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similar ...
- A1126. Eulerian Path
In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similar ...
- 【PAT甲级】1053 Path of Equal Weight (30 分)(DFS)
题意: 输入三个正整数N,M,S(N<=100,M<N,S<=2^30)分别代表数的结点个数,非叶子结点个数和需要查询的值,接下来输入N个正整数(<1000)代表每个结点的权重 ...
- 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 ...
- PAT甲级——A1155 HeapPaths【30】
In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...
随机推荐
- vue v-for 组件传值 enter传值
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- bootstrapValidator--表单校验
关于表单校验 要依次引入 <link rel="stylesheet" href="./bootstrap/css/bootstrap.min.css"& ...
- Java中的线程Thread方法之---interrupt()
前几篇都介绍了Thread中的几个方法,相信大家都发现一个相似点,那就是sleep,join,wait这样的阻塞方法都必须捕获一个InterruptedException异常,顾名思义就是一个线程中断 ...
- 今天工作整整一个月了,来记录一下(web前端)
25号,工作整整一个月了,时光飞逝, 这一个月以来,无论是工作上还是生活上,都让我成长了很多,也多了些对人生的思考… 先回顾一下找工作的那段时间吧年前找工作有多辛酸,年后找工作就有多幸运那段日子,我这 ...
- jQuery.speech实现文本转语音播报功能
先放一个实例的地址https://github.com/wenco/speech jQuery.speech是用jQuery写的扩展插件,主要是用来语音播报. 接口调用百度翻译的接口,所以存在url参 ...
- NX二次开发-UFUN点构造器UF_UI_point_construct
#include <uf.h> #include <uf_ui.h> UF_initialize(); //点构造器 char sCue[] = "点构造器" ...
- HDU6447 YJJ's Salesman-2018CCPC网络赛-线段树求区间最值+离散化+dp
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门 原题目描述在最下面. 1e5个点,问 ...
- jvm-多线程
多线程的目的 为什么要使用多线程?可以简单的分两个方面来说: 在多个cpu核心下,多线程的好处是显而易见的,不然多个cpu核心只跑一个线程其他的核心就都浪费了: 即便不考虑多核心,在单核下,多线程也是 ...
- nginx中reuqest_uri与uri的区别说明
reuqest_uri:即客户端发送来的原生请求URI,包括请求参数 uri:请求URI,不包括任何请求参数 举例说明: 1.比如客户端以 get 方式请求 /admin 页面,并且带 id 和 na ...
- 《转》python对象
http://www.cnblogs.com/BeginMan/p/3160044.html 一.学习目录 1.pyhton对象 2.python类型 3.类型操作符与内建函数 4.类型工厂函数 5. ...