search
HomeBackend DevelopmentPHP Tutorial 欧拉回路的使用&&http://acm.hdu.edu.cn/showproblem.php?pid=3018

欧拉回路的应用&&http://acm.hdu.edu.cn/showproblem.php?pid=3018

题意:给你一个图,问你最少几笔能画完该图,其中孤立的点除外

#include<cstdio>
#include<string.h>
#include<vector>
#include<string>
#define N 100005
#include<algorithm>
#include<iostream>
using namespace std;
int Father[N];
vector<int>a;//记录根节点,其长度为连通分支的个数
int in[N];
int num[N];//每个连通分支奇度顶点的个数。
bool Hash[N];
int n,m;
void init()
{
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;++i) Father[i]=i;
		memset(in,0,sizeof(in));
		memset(Hash,false,sizeof(Hash));
		a.clear();
}
int Find(int x)
{
	if(x==Father[x]) return x;
	return Father[x]=Find(Father[x]);
}
void Union(int x,int y)
{
	 x=Find(x);
	 y=Find(y);
	 if(x!=y) Father[x]=y;
}
int main()
{
	while(~scanf("%d%d",&n,&m))
	{
		init();
		for(int i=0;i!=m;++i)
		{
			int a,b;
			scanf("%d%d",&a,&b);
			Union(a,b);
			in[a]++;
			in[b]++;
		}
		int res=0;
		for(int i=1;i<=n;++i)
			{
			   int k=Find(i);
			   if(!Hash[k])
			   {
				   Hash[k]=true;
				   a.push_back(k);
			   }
			   if(in[i]&1) num[k]++;
		  }
		for(int i=0;i<a.size();++i)
		{
			int k=a[i];
			if(!in[k]) continue;
			if(num[k]==0) res++;
			else  res+=num[k]/2;
		}
		 printf("%d\n",res);
	}return 0;
}


 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP中int类型转换为字节的方法详解PHP中int类型转换为字节的方法详解Mar 06, 2024 pm 06:18 PM

PHP中int类型转换为字节的方法详解在PHP中,我们经常需要将整数类型(int)转换为字节(Byte)类型,比如在处理网络数据传输、文件处理或者加密算法等场景中。本文将详细介绍如何将int类型转换为字节类型,以及提供具体的代码示例。1.int类型与字节的关系在计算机领域,基本数据类型int表示整数,而字节(Byte)是计算机存储单位,通常是8位二进制数据

C++程序将double类型的变量转换为int类型C++程序将double类型的变量转换为int类型Aug 25, 2023 pm 08:25 PM

在C++中,int类型的变量只能保存正整数或负整数值;它们不能保存小数值。有float和double值可用于此目的。为了存储小数点后最多七位的小数,创建了双精度数据类型。整数到双精度数据类型的转换可以由编译器自动完成(称为“隐式”转换),也可以由程序员向编译器显式请求(称为“显式”转换)。在接下来的部分中,我们将介绍各种转换方法。隐式转换编译器自动执行隐式类型转换。要实现这一点,需要两个变量——一个是浮点类型,另一个是整数类型。当我们简单地将浮点值或变量分配给整数变量时,编译器将处理所有其他事情

php include和include_once有什么区别php include和include_once有什么区别Mar 22, 2023 am 10:38 AM

当我们在使用 PHP 编写网页时,有时我们需要在当前 PHP 文件中包含其他 PHP 文件中的代码。这时,就可以使用 include 或 include_once 函数来实现文件包含。那么,include 和 include_once 到底有什么区别呢?

int32的取值范围是多少int32的取值范围是多少Aug 11, 2023 pm 02:53 PM

int32的取值范围是从-2的31次方到2的31次方减1,即-2147483648到2147483647。int32是有符号的整数类型,意味着它可以表示正数、负数和零,它使用1位来表示符号位,而剩余的31位用来表示数值。由于一位被用来表示符号位,所以int32的有效位数是31位。

java int 是几位java int 是几位Mar 06, 2023 pm 04:09 PM

在java中,int是32位有符号数据类型,其变量需要32位内存;int数据类型的有效范围为-2147483648至2147483647,此范围中的所有整数称为整数字面量。一个整数字面量可以分配给一个int变量,例如“int num1 = 21;”。

int占几个字节int占几个字节Jan 22, 2024 pm 03:14 PM

int类型在不同编程语言和不同硬件平台下所占用的字节数可能会有所不同。详细介绍:1、在C语言中,int类型通常占用2个字节或4个字节。在32位系统中,int类型占用4个字节,而在16位系统中,int类型占用2个字节。在64位系统中,int类型可能占用8个字节;2、在Java中,int类型通常占用4个字节,而在Python中,int类型没有字节数限制,可以自动调整等等。

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code<form name="myform"

AMP是什么币?AMP是什么币?Feb 24, 2024 pm 09:16 PM

什么是AMP币?AMP代币是由Synereo团队于2015年创立,作为Synereo平台的主要交易货币。AMP代币旨在通过多种功能和用途,为用户提供更好的数字经济体验。AMP代币的用途AMP代币在Synereo平台中拥有多重角色和功能。首先,作为平台的加密货币奖励系统的一部分,用户能够通过分享和推广内容来获得AMP奖励,这一机制鼓励用户更积极地参与平台的活动。AMP代币还可用于在Synereo平台上推广和传播内容。用户可以通过使用AMP代币提升他们的内容在平台上的曝光率,以吸引更多观众来查看和分

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)