【PAT甲级 简单图论】1126 Eulerian Path (25分)

PAT 1126. Eulerian Path (25)-甲级 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 firs 阅读详情

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 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

以下转载自liuchuo博客,我做了局部的修改。

题目大意

如果一个连通图的所有结点的度都是偶数,那么它就是Eulerian,如果除了两个结点的度是奇数其他都是偶数,那么它就是Semi-Eulerian,否则就是Non-Eulerian~

分析

1.用邻接表存储图,用的是二维向量而不是二维数组,因为前者能超级方便地判断每个结点的度【也就是每个结点i的v[i].size()】是多少即可得到最终结果

2.注意:图必须是连通图,所以要用一个深搜判断一下连通性,从结点1开始深搜,如果最后发现统计的连通结点个数cnt != n说明是不是连通图,要输出Non-Eulerian~
 

#include <iostream>
#include <vector>
using namespace std;
vector<vector<int> > v;
vector<bool> visit;
int cnt = 0;
void dfs(int index) {
    visit[index] = true;
    cnt++;
    for (int i = 0; i < v[index].size(); i++)
        if (visit[v[index][i]] == false)
            dfs(v[index][i]);
}
int main() {
    int n, m, a, b, even = 0;
    scanf("%d%d", &n, &m);
    v.resize(n + 1);
    visit.resize(n + 1);
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &a, &b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for (int i = 1; i <= n; i++) {
        if (i != 1) printf(" ");
        printf("%d", v[i].size());
        if (v[i].size() % 2 == 0) even++;
    }
    printf("\n");
    dfs(1);
    if (even == n && cnt == n)
        printf("Eulerian");
    else if(even == n - 2 && cnt == n)
        printf("Semi-Eulerian");
    else
        printf("Non-Eulerian");
    return 0;
}

 

Mission Planner连接Autopilot保姆级教程:从USB到无线全搞定 本文提供Mission Planner连接Autopilot的全面指南,涵盖USB直连、无线数传、蓝牙适配等多种连接方案。详细讲解驱动安装、波特率匹配、性能优化等关键步骤,并分享多链路冗余配置与故障转移的高阶技巧,助你快速解决连接问题。 阅读详情

相关推荐

ABP框架实战:从零搭建多租户应用(含完整代码示例)

本文详细介绍了如何使用ABP框架从零构建多租户SaaS应用,涵盖多租户架构设计、数据隔离实现、租户管理及性能优化等核心内容。通过完整的代码示例,帮助开发者快速掌握企业级数据隔离系统的开发技巧,提升SaaS应用开发效率。

weixin_29247219的博客 263

pat甲级1126 Eulerian Path (25分)

文章目录pat甲级1126 Eulerian Path (25分)1.题意理解2.分析3.代码:(O(n))(O(n))(O(n)) pat甲级1126 Eulerian Path (25分) 1.题意理解 本题是判断题。非常简单,无需任何推论来做,只需明白定义即可: connected graphs with all vertices of even degree have an Eulerian circuit, and such graphs are called Eulerian. If there

qq_44992782的博客 168

Win10 LTSC 2021 CPU占用率飙升?KB5017308补丁修复全攻略

本文针对Windows 10 LTSC 2021系统中因wsappx进程导致的CPU占用率异常飙升问题,提供了详细的解决方案。核心在于安装微软官方发布的KB5017308补丁,该补丁能从根本上修复系统组件缺陷,使CPU占用恢复正常。文章详解了补丁的下载、安装步骤、注意事项及安装后的验证方法,是解决此问题的权威指南。

python9snake的博客 1261

PAT(甲级)2017年春季考试 PAT 1126 Eulerian Path (25 分) 欧拉路

PAT(甲级)2017年春季考试 PAT 1126 Eulerian Path (25 分) 欧拉路 【题目描述】 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 fi

weixin_46283740的博客 263

ROS学习【11】-----基于ubuntu16.04上Gazebo机器人环境搭建的传感器仿真(camera、kinect、Lidar),并通过Rviz进行数据显示

ROS学习-----基于ubuntu16.04上Gazebo机器人环境搭建的传感器仿真目录一、Gazebo环境搭建前的准备1、将搭建模型下载到我们的gazebo环境下2、升级我们的gazebo版本二、创建配置launch文件参数的world文件1、进入工程包mbot_gazebo2、创建文件夹worlds3、进入该文件夹4、创建playground.world文件5、创建room.world文件三...

qq_42451251的博客 3607

从数据同化到水文模拟:CMADS如何重塑SWAT模型的中国实践

本文探讨了CMADS数据集与SWAT模型在中国复杂地形水文模拟中的融合实践。CMADS通过高分辨率气象数据同化技术,显著提升了SWAT模型在中国特殊地理环境下的模拟精度,特别是在数据稀缺区域。文章详细分析了CMADS的技术架构、应用案例及与传统数据的性能对比,为水文研究提供了新的技术支撑。

git9versioner的博客 630

PAT甲级1126 Eulerian Path (25分)|C++实现

一、题目描述 原题链接 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

weixin_42393947的博客 253

NRF24L01学习操作教程(二)——NRF实现一对一,一对多通讯

以上内容详细介绍了,使用NRF24L01实现1对1单向通讯、1对1双向通讯、1对多双向通讯。

Joseph Wen的博客 7388

【PAT甲级】1126 Eulerian Path

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 506

SOEM主站开发篇(1):移植SOEM主站到Linux开发板

详细介绍了SOEM主站源码移植到Linux开发板上的步骤,同时演示了如何使用Linux开发板获取EtherCAT从站的PDO映射信息。

kevin1499的博客 2396

一文读懂AI协同办公领域发展和趋势

协同办公,又称OA,是指企业内部或外部各类人员之间利用信息技术来进行协作工作的一种形式。这种协作工作既可以由直接员工进行,也可以来自外部的咨询机构、合作伙伴或联营企业。协同办公的优势在于可以对资源进行有效管理和配置,各部门之间可以建立良好的协作关系,跨部门更好地实现资源共享。

女王の专属领地 2357

PAT——1126 Eulerian Path 甲级

1126 Eulerian Path题目题意代码解析AC代码参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/994805349851185152 题意 在连通图的基础上,如果所有节点的度(点作为边的起点或重点的数量之和)为偶数就是Eulerian,只有两个点的度是奇数则为Semi—Eulerian,否则就是Non-Eulerian 代码解析 通过dfs判断该图是否为连通图,在此基础上判断偶数度的数量,最终输出即可 AC代码 #

ljhsq的博客 185

C#版OpenCV:OpenCVSharp 最详细最全面教程(万字详细总结)

OpenCVSharp 是一个用于 .NET 环境的 OpenCV 包装库,它提供了一种简便的方法来利用 OpenCV 的功能进行图像和视频处理。OpenCV(Open Source Computer Vision Library)是一个开源计算机视觉和机器学习软件库,最初由 Intel 研发并发布。OpenCVSharp 让 C# 和其他 .NET 语言的开发者可以方便地访问 OpenCV 的强大功能。// 打印 OpenCV 版本信息Cv2。

仰望星空的博客 2万+

PAT甲级——1126 Eulerian Path (25 分)

1126Eulerian Path(欧拉路径) 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 ...

小熊猫的博客 482

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

PAT甲级 1126 Eulerian Path (25)

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

qq_37370420的博客 287

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

PAT 甲级 1126  Eulerian Path

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

漫浸天空的雨色的备忘录~ 671

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

PAT甲级1126 Eulerian Path (25 分)

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

Dexter 266

1126 Eulerian Path (25 分)--PAT甲级

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

laplacebh的博客 474

PAT甲级A1126 Eulerian Path (25 分)

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 firs...

vir_lee的博客 259

【刷题】A1126 Eulerian Path-PAT甲级

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

十三w~w博客 248

PAT甲级 -- 1126 Eulerian Path (25 分)

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 firs...

猪の成长日记 252

PAT_A 1126. Eulerian Path (25)

1126. Eulerian Path (25)图论 欧拉回路 pat甲级考试经验总结

longtails的博客 1436

1126 Eulerian Path-PAT甲级

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 firs...

amf12345的博客 247

PAT 甲级 1126 Eulerian Path (25 分)

思路: 1.结点度数全为偶数的为欧拉回路; 2.度数为奇数的结点数量为1或大于3的为非欧拉路径; 3.度数为奇数的结点数量为2的为欧拉路径; (PS:很多大佬讲这是根据题意得出的,本杠精小声bb一下,除了第一点题目也没说数量为2的就一定有欧拉路径,当然了每个人理解可能不一样,2、3两点稍微推理下也能得出来) 4.非连通图没有欧拉回路或者欧拉路径; 代码: #include<iostream&...

Yuhan的博客 224

PAT 甲级1126 Eulerian Path

1126 Eulerian Path 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 s

cyberickk blog 241

PAT甲级7-3 1126 Eulerian Path (25分)

算法笔记总目录 关键英语单词解释 1126 Eulerian Path (25分) 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

0 225
上一篇: 【PAT甲级】堆的专题复习
下一篇: 【PAT甲级 简单图论】1122 Hamiltonian Cycle (25)
浒鱼鱼
博客等级 码龄11年 287粉丝 70原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值