PAT甲级1126

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 阅读详情

PAT甲级1126

题目大意:给定总节点数,总边数,让你判断是否是一个Eulerian路径。Eulerian路径:一个无向连通图所有的节点的度都是偶数;semi-Eulerian路径:一个无向连通图只有两个度为奇数的节点,剩下的节点度都是偶数;non-Eulerian:超过两个节点度为奇数。
统计度的问题,循环遍历每个节点累加度。之后遍历degree数组统计奇数度的个数即可。注意这里首先要判断图是否连通(测试点3)。

#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#define MAXN 505
using namespace std;

int n;
int edge[MAXN][MAXN];
bool visit[MAXN];
void DFS(int index){
	if(visit[index]) return ;
	visit[index]=true;
	for(int i=1;i<=n;i++)
		if(edge[index][i]>0&&!visit[i])
			DFS(i);
}
bool isConnected(){
	bool flag=true;
	for(int i=1;i<=n;i++)
		if(!visit[i]) flag=false;
	return flag;
}
int main(){
	int m,v1,v2;
	scanf("%d%d",&n,&m);
	int degree[n+1];
	for(int i=1;i<=n;i++){
		fill(edge[i],edge[i]+n+1,0);
		fill(degree,degree+n+1,0);
	}
	for(int i=0;i<m;i++){
		scanf("%d%d",&v1,&v2);
		edge[v1][v2]=edge[v2][v1]=1;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(edge[i][j]>0) degree[i]++;
		}
	}
	DFS(1);
	int oddcnt=0;
	for(int i=1;i<=n;i++){
		if(i!=1) printf(" ");
		printf("%d",degree[i]);
		if(degree[i]%2!=0){
			oddcnt++;
		}
	}
	printf("\n");
	if(!isConnected()){
		printf("Non-Eulerian");
	}else{
		if(oddcnt==0) printf("Eulerian");
		else if(oddcnt==2) printf("Semi-Eulerian");
		else printf("Non-Eulerian");
	}
	system("pause");
	return 0;
}

湿敏电阻HR202的两种驱动方案实测:IO充放电法 vs. 交流方波ADC法,哪个更适合你? 本文深入评测湿敏电阻HR202的两种驱动方案:IO充放电法和交流方波ADC法。通过原理图分析、精度实测和资源占用对比,揭示交流方波ADC法在精度和稳定性上的优势,特别适合长期监测场景。同时提供IO充放电法在资源受限情况下的应用建议,帮助工程师根据项目需求做出最优选择。 阅读详情

相关推荐

Couldn‘t find device with uuid 恢复LVM元数据 linux

Couldn't find device with uuid 恢复LVM元数据 linux欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Markdown编辑器 你好! 这是你第一次使

m0_57559579的博客 7166

PAT (Advanced Level) Practise 1126 Eulerian Path (25)

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

Occult 805

解决ADS1.2报错Cannot obtain license

报错如下 将licenses文件下的license内容进行修改: 修改为如下内容即可。 # # Generated on 2021-dec-1 by licwizard # PACKAGE ads armlmd 1.200 E32F0DE5161D COMPONENTS="armasm compiler bats armulate axd adwu fromelf armlink codewarrior armsd" INCREMENT ads armlmd 1.200 permanent uncounte

qq_46110320的博客 3462

PAT甲级 1126 - Eulerian Path

根据题目所给的条件进行判断即可。 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 ...

Mr0cheng的专栏 376

导数在工程与AI中的12个实战应用解析

导数作为数学中的基本概念,本质是描述变化率的工具,其核心价值在于将非线性问题局部线性化处理。从原理上看,通过极限过程捕捉函数瞬时变化特性,使工程师能精确控制系统动态行为,帮助科学家量化自然规律变化速率。在技术实现层面,现代符号计算(如Mathematica)、数值计算(如MATLAB)和自动微分(如PyTorch)工具链的发展,大幅提升了导数计算的效率与精度。典型应用场景涵盖机械控制(如ABS防抱死系统)、金融工程(如期权希腊值计算)、医疗影像(如Canny边缘检测)等领域。特别在机器学习中,反向传播算法依

weixin_35509395的博客 316

microblaze之Video Processing Subsystem调试误区

内容:总结video processing subsystem调试中遇到的问题,以及在解决问题中的思路方法论,引为前车之鉴。 1,我的目的是希望采用vps中的scaler模块对图像进行拉伸缩小。IP的配置如下: 2,整个系统的框架图如下,仅比上期的内容增加了scaler模块,如下: 3,查手册,可以知道这个scaler only组件分成了hscale,vscale和GPIO,其中GPIO是控制上下游stream流控设备复位用,暂时忽略。 hscale和vscale的寄存器空间如下,主要关注图

YDY5659150的专栏 3555

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

CentOS 7 安装 Python 3.10

我这里已经软链接了,正常未链接之前是python->python2.7而不是python3.10。python2.7默认安装是在 /usr/bin目录中,切换到/usr/bin/更改yum配置,因为其要用到python2才能执行,否则会导致yum不能正常使用。2. 安装 Python 3.10 必需的 openssl >= 1.1.1。默认的centos7是没有安装pip,先添加epel扩展源。/usr/bin/python 修改为如下。添加软链接,将原来的链接备份。添加python3的软链接。

bensonyang888的博客 2905

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

STM32F103ZE驱动PMW3901光流模块,从SPI配置到数据读取的完整避坑指南

本文详细解析了STM32F103ZE驱动PMW3901光流模块的全过程,从SPI配置、硬件连接到数据读取与处理,提供了完整的避坑指南。重点介绍了SPI参数配置、初始化序列优化、运动数据滤波等关键技巧,帮助开发者快速实现精准的光流检测。

weixin_42631411的博客 514

Python-编写点云处理软件(二)点云软件ui制作之仿CC界面

至本篇结束,我们已经能够获得一个有点模子的界面了,但是具体的功能还没有编写,后续的文章将逐渐完善功能。

weixin_43894929的博客 3953

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

IEM模型,地表粗糙度模拟

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

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

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

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

【PAT甲级】1126 Eulerian Path

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

Newin2020的博客 506

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

PAT甲级1126~1130|C++实现

PAT甲级1126 Eulerian Path (25分)|C++实现 PAT甲级1127 ZigZagging on a Tree (30分)|C++实现 PAT甲级1128 N Queens Puzzle (20分)|C++实现 PAT甲级1129 Recommendation System (25分)|C++实现 PAT甲级1130 Infix Expression (25分)|C++实现

weixin_42393947的博客 1945

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

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

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甲级 1126 欧拉路径

PAT甲级 1126 欧拉路径

赵小轩的博客 292

PAT 甲级 1126 PAT Ranking 个人错误总结

这个题还要dfs一下判断是否为连通图。 要不就只有20分,我以为默认联连通图了。 #include<bits/stdc++.h> using namespace std; int d[501]; bool ll[501][501]; bool flag[501]; void dfs(int root){ flag[root]=true; for(int i=1;i<501;i++){ if(ll[root][i]==true&&flag[i]==false)dfs(

☁的博客 113

PAT甲级 1126 Eulerian Path

题目链接:点击打开链接思路:按照题目给出的定理判断即可,同时该定理比较重要,要熟记。#include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;iostream&gt; #include &lt;queue&gt; using namespace std; int degree[505]; int cnt,head[505]; int...

不忘初心 326

PAT甲级 1126 欧拉回路

分数 25。

qq_62368250的博客 176
上一篇: PAT甲级1122
下一篇: PAT甲级1130
zerohawk
博客等级 码龄8年 3粉丝 78原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值