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<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int G[][] = {,}, visit[] = {};
int N, M;
void DFS(int vt){
visit[vt] = ;
for(int i = ; i <= N; i++){
if(G[vt][i] != && visit[i] == )
DFS(i);
}
}
int main(){
scanf("%d%d", &N, &M);
for(int i = ; i < M; i++){
int v1, v2;
scanf("%d%d", &v1, &v2);
G[v1][v2] = G[v2][v1] = ;
}
int odds = , even = , cnt = ;
for(int i = ; i <= N; i++){
int sum = ;
for(int j = ; j <= N; j++){
sum += G[i][j];
}
if(i == N)
printf("%d\n", sum);
else printf("%d ", sum);
if(sum % == ){
odds = ;
}else{
even = ;
cnt++;
}
}
DFS();
for(int i = ; i <= N; i++)
if(visit[i] == ){
printf("Non-Eulerian");
return ;
}
if(even == ){
printf("Eulerian");
}else if(cnt == ){
printf("Semi-Eulerian");
}else printf("Non-Eulerian");
cin >> N;
return ; }

总结:

1、容易被忽略的:Semi-Eulerian和 Eulerian都是建立在连通图的基础上。最开始忽略了连通图的条件,结果有一个测试点过不去。应该先判断是否连通,不连通为 Non-Eulerian。

A1126. Eulerian Path的更多相关文章

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

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

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

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

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

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

  4. PAT_A1126#Eulerian Path

    Source: PAT A1126 Eulerian Path (25 分) Description: In graph theory, an Eulerian path is a path in a ...

  5. 1126 Eulerian Path (25 分)

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

  6. Graph | Eulerian path

    In graph theory, a Eulerian trail (or Eulerian path) is a trail in a graph which visits every edge e ...

  7. PAT1126:Eulerian Path

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

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

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

  9. PAT 甲级 1126 Eulerian Path

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

随机推荐

  1. pHP生成唯一单号

    这几天一直在写个人使用的用户中心,虽然期间遇到不少的问题,但还是一点点的都解决了,也从制作期间学到不少的知识,今天就说一说利用PHP生成订单单的方法. 订单号,大家都不陌生,无论从在网上购物,还是在线 ...

  2. longquan

    /** * 登录后将数据填写到主数据 */ public void login(String login_nr) { //File f = new File(android.os.Environmen ...

  3. python之路--初识html前端

    一.HTML文档结构 最基本的HTML文档: <!DOCTYPE html> <html lang="zh-CN"> #这个lang表示语言,zh-CN是中 ...

  4. 从git中删除 .idea 目录

    将.idea目录加入ignore清单: $ echo '.idea' >> .gitignore   从git中删除idea: $ git rm —cached -r .idea 3 将. ...

  5. DAY06、元组、字典、集合

    一.元组 1.定义:参数为for可以循环的对象 t1 = (1, 2)     t2 = tuple((1, 2))     t3 = (1, )        #定义一个只有一个值的元组 2.常用操 ...

  6. Git官方推荐用书

    用Git看了N多的Blog, 乱七八糟. 官方的推荐用书写得最好,最权威.还可以下载pdf.记录一笔. https://git-scm.com/book/zh/v2/

  7. OSError: mysql_config not found

    使用Python3开发一个管理平台,用MySQL数据库存放元数据.使用pip安装mysqlclient模块时出现“OSError: mysql_config not found”错误. 解决: # a ...

  8. 怎样利用ADO中的adoquery进行缓存更新?????(100分)

    我用BDE时,用query与updatesql相结合进行缓存更新,但是在ADO中没有updatesql,只有用adoquery,在DBGRID中,用CANCELUPADTE,只能取消一条记录,烦恼不已 ...

  9. 三种bean创建方式

  10. UVA 11988 Beiju Text

    https://vjudge.net/problem/UVA-11988 题目 你有一个破损的键盘.键盘上所有的键都可以正常工作,但有时候Home键或者End键会自动按下.你并不知道键盘存在这一问题, ...