HDOJ3018 Ant Trip(欧拉回路 + 并查集)

判欧拉回路或求一个图中欧拉图的个数 判欧拉图两个条件首先联通,其次度全部为欧度。那么就很easy了。 题目:hdoj1878求一个图中欧拉图的个数。 首先通过连通性求出各个子图,然后求子图中奇数度的个数cnt,cnt/2为欧拉图的个数。若子图没有奇数度,则为一个欧拉回路。 题目:hdoj3018Ant Trip 注意这个题目中可能出现孤立点,不算入欧拉图中。AC代码:include include include includ 阅读详情

Ant Trip

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2055    Accepted Submission(s): 796


Problem Description
Ant Country consist of N towns.There are M roads connecting the towns.

Ant Tony,together with his friends,wants to go through every part of the country. 

They intend to visit every road , and every road must be visited for exact one time.However,it may be a mission impossible for only one group of people.So they are trying to divide all the people into several groups,and each may start at different town.Now tony wants to know what is the least groups of ants that needs to form to achieve their goal.
 

Input
Input contains multiple cases.Test cases are separated by several blank lines. Each test case starts with two integer N(1<=N<=100000),M(0<=M<=200000),indicating that there are N towns and M roads in Ant Country.Followed by M lines,each line contains two integers a,b,(1<=a,b<=N) indicating that there is a road connecting town a and town b.No two roads will be the same,and there is no road connecting the same town.
 

Output
For each test case ,output the least groups that needs to form to achieve their goal.
 

Sample Input
3 3 1 2 2 3 1 3 4 2 1 2 3 4
 

Sample Output
1 2
Hint
New ~~~ Notice: if there are no road connecting one town ,tony may forget about the town. In sample 1,tony and his friends just form one group,they can start at either town 1,2,or 3. In sample 2,tony and his friends must form two group.
 



经过每条边一次,每次一笔画,问你最少画多少次,孤立点不算其中。通过并查集判断连通集的数量,点的度数奇偶性判断。

笔画数 = 奇度数 + 欧拉回路数。


AC代码:


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "vector"
using namespace std;
const int MAXN = 1e5 + 5;
int n, m, par[MAXN], deg[MAXN], odd[MAXN];
bool vis[MAXN];
vector<int> v;
int find(int x)
{
	if(x == par[x]) return x;
	return par[x] = find(par[x]);
}
int main(int argc, char const *argv[])
{
	while(scanf("%d%d", &n, &m) != EOF) {
		v.clear();
		memset(deg, 0, sizeof(deg));
		memset(odd, 0, sizeof(odd));
		memset(vis, false, sizeof(vis));
		for(int i = 1; i <= n; ++i) 
			par[i] = i;
		for(int i = 0; i < m; ++i) {
			int a, b;
			scanf("%d%d", &a, &b);
			int fa = find(a), fb = find(b);
			deg[a]++, deg[b]++;
			par[fb] = fa;
		}
		for(int i = 1; i <= n; ++i) {
			int x = find(i);
			if(!vis[x]) {
				v.push_back(x);
				vis[x] = true;
			}
			if(deg[i] & 1) odd[x]++;
		}
		int ans = 0;
		for(int i = 0; i < v.size(); ++i) {
			int x = v[i];
			if(deg[x] == 0) continue;
			if(odd[x] == 0) ans++;
			else ans += odd[x] >> 1;
		}
		printf("%d\n", ans);
	}
	return 0;
}


AppStore逆向分析:从网络抓包到自动化模拟的完整实践 在移动应用生态中,理解客户端与服务器之间的通信协议是进行自动化测试、数据分析和系统集成的关键技术基础。通过分析网络请求与响应,可以深入理解认证、会话管理和数据交换的原理,这对于构建稳定的自动化流程至关重要。其技术价值在于能够实现合法场景下的流程模拟,例如应用元数据监控、沙盒环境测试或内部工具开发。在实际应用场景中,开发者常需处理登录态维持、请求签名验证及风控策略应对等挑战。本文聚焦于AppStore这一封闭生态,详细拆解了其登录、查询等核心环节的通信机制,并探讨了使用Python结合抓包工具进行安全逆向分析 阅读详情

相关推荐

JDK8升级JDK17过程中遇到的那些坑

JDK8虽然非常好,但是JDK版本已经发布到JDK20了,且JDK8后的版本升级了很多新的特性,如模块化、ZGC以及虚拟线程、结构性并发等,也是非常有吸引力的,所以决定将基于JDK8的项目升级到最近的LTS版本JDK17。

BASK2312的博客 6685

hdoj3018 Ant Trip 欧拉回路

Ant TripProblem DescriptionAnt Country consist of N towns.There are M roads connecting the towns.Ant Tony,together with his friends,wants to go through every part of the country. They intend to visit e

dreamnyc 580

二、基于C语言的JPEG解码代码详解

// JPEG解码 // 输入JPEG后输出Bitmap #include <stdio.h> #include <stdlib.h> #pragma warning(disable : 4996) unsigned int BuffIndex; // JPEG数据的位置 unsigned int BuffSize; // JPEG数据的大小 unsigned int BuffX; // 图像的横向尺寸 unsigned int BuffY; //

m0_37633745的博客 4455

hdoj 3018 Ant Trip(无向图欧拉路||一笔画+并查集)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3018 思路分析:题目可以看做一笔画问题,求最少画多少笔可以把所有的边画一次并且只画一次; 首先可以求出该无向图中连通图的个数,在每个无向连通图中求出需要画的笔数再相加即为所求。在一个无向连通图中,如果所有的点的度数为偶数则存在一个欧拉回路, 则只需要画一笔即可;如果图中存在度数为奇数的...

aqjh9999的博客 170

实战指南:用Python实现ONVIF WS-Discovery设备发现(附完整代码)

本文提供了一份详细的实战指南,介绍如何使用Python实现基于ONVIF标准的WS-Discovery设备发现协议。文章深入解析了协议原理、网络通信模型,并提供了完整的代码实现,帮助开发者快速构建智能安防和物联网应用中的设备自动发现工具,有效提升网络设备集成与管理的效率。

chair的专栏 1113

AutoSAR配置视频讲解:总目录

AutoSAR实验视频讲解:闪烁一颗LED实验【总目录】 欢迎大家来到雪云飞星的《AutoSAR实验视频讲解》,本专栏是一个关于AutoSAR的闪烁LED灯的实验课程,一共8节课,每节课的视频都放在文章最后,传送门如下: 前言 AutoSAR实验视频讲解:简介 EB 的Mcal配置 AutoSAR实验视频讲解:Mcal配置 DaVinci Cfg配置 AutoSAR实验视频讲解:新建DaVinci工程 AutoSAR实验视频讲解:Os配置(预计2021-3-10更新) AutoSAR实验视频讲解:检查校验报

雪云飞星的博客 2万+

HDOJ 3018 Ant Trip(欧拉回路判断几笔画问题)

Ant Trip Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2178    Accepted Submission(s): 845 Problem Description Ant Country consis

Chunzhen的博客 766

团体程序设计天梯赛竞赛题--登顶题【L3-039 攀岩】

登顶级 3 道题,每道题 30 分,满分为 90 分。

Pretty Boy Fox的博客 653

【欧拉回路】 HDOJ 3018 Ant Trip

结论:一个连通块里构成欧拉回路的最少起点数=max(1, 连通块里度为奇数的个数)。。。 #include #include #include #include #include #include #include #include #include #include #include #include #include #define maxn 100

yysys 462

手把手教你完成基于YOLOv8的水果/商品/食堂/蔬菜/饮料/书籍识别与计价系统,前台+后台管理系统

手把手教你完成基于YOLOv8的商店的水果/商品/食堂/蔬菜/饮料/书籍识别与计价系统,前台+后台管理员系统,可进行目标检测的操作和展示,实现对图片、视频和摄像头的实时目标检测

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 2456

让 ABAP 开发者也能做出高质量 SAP Fiori:到底需要掌握多少前端知识?

文章摘要: 随着SAP技术演进,ABAP开发者的角色边界正在重构。传统SAP GUI时代的全栈开发模式逐渐转向RAP+Fiori Elements的新范式,其中关键技术变化包括: 开发模式转变:从前后端耦合转向RAP模型驱动开发,通过CDS注解实现UI意图表达 分工优化:Fiori Elements模板处理80%标准UI需求,Flexible Programming Model解决20%差异化需求 效率提升:注解驱动开发可在RAP建模阶段同步定义UI结构,大幅缩短交付周期 工具整合:SAP提供从建模到部署的

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 349

HDOJ 3018-Ant Trip

Ant Trip Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3273    Accepted Submission(s): 1305 题目链接:点击打开链接 Problem Description

别止的博客 261

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

HDU 3018 Ant Trip

 http://acm.hdu.edu.cn/showproblem.php?pid=3018

思维迷宫 474

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

HDU-3018-Ant Trip

HDU-3018-Ant Trip http://acm.hdu.edu.cn/showproblem.php?pid=3018 这道题就是求一个无向图能够最小几笔画的问题,对于每一个连通分图,如果是欧拉回路,一笔可以画成;否则就是奇数次数的点的个数的一半 #include #include #include #include #include using namespace std; in

comeace的程序人生 412

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

[欧拉回路] hdu 3018 Ant Trip

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3018 Ant Trip Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1658Accepted Su...

weixin_30319097的博客 77

HDU3018 Ant Trip 欧拉路径

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3018 题目大意:n个蚂蚁村庄之间有m条道路,一群蚂蚁想要遍历所有的村庄,且每条道路只走一次,问至少需要把这群蚂蚁分成多少组才能实现目标。 分析:我们假设n个村庄之间有k个连通分量,对于每一个连通分量,如果存在欧拉路径,那么该分量需要一组蚂蚁就行;如果不存在欧拉路径,我们知道,要想遍

AC_Gibson的专栏 715

HDOJ 3018 - Ant Trip 判断一个无向图由由多少个欧拉(通/回)路构成..注意没有边的点不考虑..

题意:                       给一个无向图..问由多少个欧拉(通/回)路构成               题解:                       我是觉得首先要找出每一个联通块..在一个联通块中..两个奇数度的点可以构一条通路...虽然不知道怎么证明..感觉上在一个联通块上最少需要的一笔画为其max(1,其奇数度点数/2)...1是因为若此联通块没有奇数度点

zzyzzy12 1023

HDOJ1717 小数化分数2(模拟)

小数化分数2 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3923    Accepted Submission(s): 1592 Problem Description Ray 在数学课上听老师说,任何小数都

GKHack's Blog 3647

HDOJ1495 非常可乐(bfs)

题目链接:点击打开链接 定义结构体保存当前状态的m, n, s杯中的可乐,t表示倒可乐次数。读入m, n, s后保证m bfs结束的条件是m杯中无可乐,也就是当前n杯的可乐与当前s杯的可乐相等,且n杯的可乐为总可乐体积的一半。接下来就是s倒入 m,s倒入n,m倒入n,n倒入m,m倒入s,n倒入s的6种情况,如果不满足题意最后则输出NO。 AC代码: #include "

GKHack's Blog 2005

HDOJ1215 七夕节(暴力 & 筛选法)

七夕节 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 35637    Accepted Submission(s): 11170 Problem Description 七夕节那天,月老来到数字王国,他在城门上

GKHack's Blog 1887

POJ2250 Compromise(dp)

题目链接:点击打开链接 给出两段字符串数组, 每段以"#"结尾,  要求输出两段字符串数组最长的公共字符串. lcs题目, 增加了一个flag数组保存字符串比较结果, 用于最后递归数据答案. AC代码: #include "iostream" #include "cstdio" #include "cstring" #include "algorithm" using na

GKHack's Blog 1459

BestCoder Round #62 (div.2) HDOJ5564 Clarke and digits(dp + 快速幂)

Clarke and digits Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 88    Accepted Submission(s): 44 Problem Description Clarke is a

GKHack's Blog 1434

POJ1368 & HDOJ1116 Play on Words(欧拉回路 + 并查集)

Play on Words Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 10844   Accepted: 3695 Description Some of the secret doors contain a very interesting word p

GKHack's Blog 1363

BestCoder Round #65 HDOJ5592 ZYB's Premutation(树状数组+二分)

ZYB's Premutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 638    Accepted Submission(s): 302 Problem Description ZYB has

GKHack's Blog 1348

BestCoder Round #54 (div.2) HDOJ 5429 Geometric Progression(模拟)

Geometric Progression Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 316    Accepted Submission(s): 86 Problem Description Determi

GKHack's Blog 1259
上一篇: Codeforces Round #302 (Div. 1) 543A Writing Code(dp)
下一篇: POJ1041 John's trip(欧拉回路 + 并查集 + dfs)
GKHack
博客等级 码龄11年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值