https://pintia.cn/problem-sets/994805342720868352/problems/994805349851185152

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
 

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
int N, M;
vector<int> v[maxn];
int vis[maxn];
int step = 0; void dfs(int st) {
vis[st] = 1;
step ++;
for(int i = 0; i < v[st].size(); i ++) {
if(vis[v[st][i]] == 0)
dfs(v[st][i]);
}
} int main() {
scanf("%d%d", &N, &M);
memset(vis, 0, sizeof(vis));
while(M --) {
int a, b;
scanf("%d%d", &a, &b);
v[a].push_back(b);
v[b].push_back(a);
} int cnt = 0;
for(int i = 1; i <= N; i ++) {
printf("%d", v[i].size());
printf("%s", i != N ? " " : "\n");
if(v[i].size() % 2 == 0) cnt ++;
} dfs(1);
if(step != N) printf("Non-Eulerian\n");
else {
if(cnt == N) printf("Eulerian\n");
else if(cnt == N - 2) printf("Semi-Eulerian\n");
else printf("Non-Eulerian\n");
}
return 0;
}  

题目意思是判断每个点的度 都是偶数的话输出 Eulerian 只有两个点的度是奇数其余都是偶数的话输出 Semi-Eulerian 否则输出 Non-Eulerian 要注意 dfs 判断是不是一个连通图

新年快乐 不好的事情就留在上一年吧 今年一定要有不一样 

PAT 甲级 1126 Eulerian Path的更多相关文章

  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

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

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

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

  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. 1126 Eulerian Path (25 分)

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

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

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

  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 (25)

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

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

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

随机推荐

  1. This assembly may have been downloaded from the Web. ......

    错误消息例如: Error 6 Could not load the assembly file:///D:\me\Projects\DLL\Newtonsoft.Json\Portable40\Ne ...

  2. JavaEE笔记(一)

    Hibernate Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全自动的orm框架,hibernate可以自 ...

  3. 苏州Uber优步司机奖励政策(4月24日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  4. 2 python介绍

    1.Python介绍:龟叔 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,Guido开始写Python语言的编译器.Python这个名字,来自Gui ...

  5. 18-[模块]-shutil

    shutil模块 高级的 文件.文件夹.压缩包 处理模块 (1)文件操作 shutil.copyfileobj(fsrc, fdst[, length]) 将文件内容拷贝到另一个文件中 import ...

  6. 【HEOI2016】序列

    题面 题解 很像最长不下降子序列对吧(废话) 设$up[i]$和$down[i]$分别表示$i$最大最小能取多少 注意到: $$ f[i] = max_j\left\{f[j]\right\} + 1 ...

  7. 【JLOI2013】卡牌游戏

    题面 题解 概率$dp$ 设$f[i][j]$表示还剩$i$个人时,第$j$个人获胜的概率. 边界$f[1][1] = 1$ 转移: 枚举庄家抽到的卡牌$k$,得到这一轮被淘汰的位置$c$. 可以知道 ...

  8. C#中如果类的扩展方法和类本身的方法签名相同,那么会优先调用类本身的方法

    新建一个.NET Core项目,假如我们有如下代码: using System; namespace MethodOverload { static class DemoExtension { pub ...

  9. P3707 [SDOI2017]相关分析

    P3707 [SDOI2017]相关分析 线段树裸题?但是真的很麻烦QAQ 题目给的式子是什么不用管,大力拆开,就是\(\frac{\sum x_iy_i-\overline xy_i-\overli ...

  10. NO--16 vue之父子组件传值

    先创建项目并运行 vue init webpack-simple templatecd templatenpm inpm run dev 一.子组件访问父组件的数据 方式一 :子组件直接访问父组件的数 ...