1126. Eulerian Path (25)

时间限制
300 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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 思路
判断一个图:
1)是不是欧拉图。
2)半欧拉图。
3)二者都不是。 1.邻接表存储图,dfs先确定连通性。不连通则为3)
2.在图连通的基础上确定是欧拉图还是半欧拉图。点的度数全为偶数为欧拉图,恰好有两个点度数为奇数是半欧拉图,其余情况二者皆不是。 代码
#include<vector>
#include<iostream>
using namespace std;
int cnt = 0;
vector<bool> isvisit(501,false); void dfs(int root,const vector<vector<int>>& graph)
{
isvisit[root] = true;
cnt++;
for(int i = 0;i < graph[root].size();i++)
{
if(!isvisit[graph[root][i]])
dfs(graph[root][i],graph);
}
} int main()
{
int N,M;
while(cin >> N >> M)
{
vector<vector<int>> vertices(N+1);
for(int i = 0;i < M;i++)
{
int a,b;
cin >> a >> b;
vertices[a].push_back(b);
vertices[b].push_back(a);
}
int countOdds = 0;
for(int i = 1;i <= N;i++)
{
if(i == 1)
cout << vertices[i].size();
else
cout << " " << vertices[i].size();
if(vertices[i].size() % 2 != 0 )
{
countOdds++;
}
}
cout << endl;
dfs(1,vertices); if(cnt == N && countOdds == 0)
cout << "Eulerian" << endl;
else if(cnt == N && countOdds == 2)
cout << "Semi-Eulerian" << endl;
else
cout << "Non-Eulerian" << endl;
}
}

  

PAT1126:Eulerian Path的更多相关文章

  1. Graph | Eulerian path

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

  2. A1126. Eulerian Path

    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 分)——连通图,入度

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

  4. 1126 Eulerian Path (25 分)

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

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

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

  6. PAT 甲级 1126 Eulerian Path

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

  7. PAT 1126 Eulerian Path[欧拉路][比较]

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

  8. PAT甲级——1126 Eulerian Path

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

  9. PAT 1126 Eulerian Path

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

随机推荐

  1. 使用Multiplayer Networking做一个简单的多人游戏例子-2/3(Unity3D开发之二十六)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/51007512 ...

  2. DB 查询分析器 6.03 如何灵活、快捷地操作国产达梦数据库

    DB 查询分析器 6.03 如何灵活.快捷地操作国产达梦数据库 马根峰 (广东联合电子服务股份有限公司, 广州 510300) 摘要       本文详细地介绍了"万能数据库查询分析器&qu ...

  3. android https安全连接

    如果不需要验证服务器端证书,直接照这里做 [java] view plaincopy public class Demo extends Activity { /** Called when the  ...

  4. web报表工具finereport常用函数的用法总结(数组函数)

    ADD2ARRAY ADDARRAY(array,insertArray, start):在数组第start个位置插入insertArray中的所有元素,再返回该数组. 示例: ADDARRAY([3 ...

  5. HBase开启LZO

    hbase只支持对gzip的压缩,对lzo压缩支持不好.在io成为系统瓶颈的情况下,一般开启lzo压缩会提高系统的吞吐量.但这需要参考具体的应用场景,即是否值得进行压缩.压缩率是否足够等等. 想要hb ...

  6. java--交通灯管理系统

    转载请申明出处:http://blog.csdn.net/xmxkf/article/details/9944947 .交通灯管理系统的业务和需求分析 交通灯管理系统的项目需求: 模拟实现十字路口的交 ...

  7. 从ruby实现时间服务器ntp同步功能也谈“逆向工程”

    本猫以前写asm和C的时候常常不忘"逆向"一把,后来写驱动的时候也用VM之类的搭建"双机"调试环境进行调试:也对于一些小的软件crack cd-key神马的不亦 ...

  8. https认证

    HTTPS认证 说明 1. HTTPS协议的站点信息更加安全,同时可降低网站被劫持的风险,如网站同时存在HTTP和HTTPS站点,可使用本工具进行认证,便于百度搜索识别网站HTTP与HTTPS之间的对 ...

  9. MacOS软件默认安装路径

    缘起 在用苹果电脑后,很多软件安装后并不只是简单的将所有的文件都放到/Applications目录里,尤其是一些开发用的软件.这就导致要修改一些软件的配置很不方便,总是需要各种查找.为了防止以后忘记这 ...

  10. RESTful小拓展

    RESTful 即Resource Representation State Transfer 相对应Resource 资源层,Representation 表现层,State Transfer状态转 ...