Accept: 238 Submit: 420
Time Limit: 3000 mSec Memory Limit : 32768 KB
Problem Description
You have won a collection of tickets on luxury cruisers. Each ticket can be used only once, but can be used in either direction between the 2 different cities printed on the ticket. Your prize gives you free airfare to any city to start your cruising, and free airfare back home from wherever you finish your cruising.
You love to sail and don't want to waste any of your free tickets. How many additional tickets would you have to buy so that your cruise can use all of your tickets?
Now giving the free tickets you have won. Please compute the smallest number of additional tickets that can be purchased to allow you to use all of your free tickets.
Input
There is one integer T (T≤100) in the first line of the input.
Then T cases, for any case, the first line contains 2 integers n, m (1≤n, m≤100,000). n indicates the identifier of the cities are between 1 and n, inclusive. m indicates the tickets you have won.
Then following m lines, each line contains two integers u and v (1≤u, v≤n), indicates the 2 cities printed on your tickets, respectively.
Output
Sample Input
Sample Output
题意:
给出 T (<= 100)个 case,后每个 case 首先给出 N 和 M,代表有 N 个节点,M 条边,问最少要增加多少条边使能遍历给出的所有边。
思路:
欧拉通路。只有 0 个或者 2个 奇度数结点时存在一条欧拉通路。故判断有多少个奇度数结点即可。若不存在则说明已存在欧拉通路,输出0。若存在奇度数结点,则必然从一个奇度数结点出发到另外一个奇度数结点。每增加一条边就可以使两个奇数结点变为偶数,所以应该增加的边数是 (ans - 2)/ 2 条。
AC:
#include <cstdio> #include <cstring> using namespace std; const int NMAX = 100005; int deg[NMAX]; int main() { int t; scanf("%d", &t); while(t--) { int n, m; scanf("%d%d", &n, &m); memset(deg, 0, sizeof(deg)); while(m--) { int a, b; scanf("%d%d", &a, &b); ++deg[a]; ++deg[b]; } int ans = 0; for (int i = 1; i <= n; ++i) { if (deg[i] % 2) ++ans; } if (!ans) printf("0\n"); else printf("%d\n", (ans - 2) / 2); } return 0; }
相关推荐
【标题】"Tmall_Tickets-master.rar" 是一个与天猫平台相关的压缩文件,根据描述,它包含了一个天猫茅台抢购软件。这个软件可能是一个浏览器插件,设计用于帮助用户更高效地参与天猫上的茅台酒抢购活动。茅台酒作为...
"Python-tickets通过CLI进行票务操作"的项目旨在利用Python构建一个命令行界面(CLI)工具,使得用户能够方便地进行票务管理。CLI工具通常以简洁、高效的方式交互,对于快速执行任务和自动化流程非常理想。 首先,...
在本文中,我们将深入探讨基于Laravel框架的“tickets”项目开发。Laravel是一个流行的、开源的PHP框架,它为Web应用开发提供了优雅的工具和结构,使得开发者能够快速、高效地构建高质量的Web应用程序。 首先,让...
### 欧拉路径问题详解 #### 一、问题概述 **欧拉路径**是指在一个图中找到一种路径,使得这条路径能且只能通过每条边一次。这种路径也被称为“一笔画”问题。根据图的不同类型(无向图或有向图),欧拉路径的存在...
Tickets.pdf
标题中的"tickets-0.2.0-py3-none-any.whl"是一个Python库的发行文件,这通常是一个轮子(wheel)文件,是Python软件包的二进制格式。这种格式的文件使得安装Python库更为高效,因为它可以直接被Python的pip工具安装...
- `support_tickets.sql`:这是一个SQL文件,很可能包含了数据库结构和初始数据,用于快速设置和初始化数据库。 - `upload`:可能是一个目录,用于存储用户上传的附件或证据文件。 3. **开源软件的优势**: - ...
**Python库 django_zendesk_tickets-0.8-py2-none-any.whl 深度解析** `django_zendesk_tickets-0.8-py2-none-any.whl` 是一个针对Python开发者的库,用于集成Django框架与Zendesk客服系统。这个库允许开发者在...
095&096-Tickets, Please..lrc
java java_leetcode题解之Minimum Cost For Tickets.java
数据集“Flights & Tickets 航班机票数据集.7z”是一个专门针对航班和机票搜索趋势的研究资源,它提供了Google搜索引擎对于此类关键词的排行信息。这个数据集的独特之处在于其持续性,每15天更新一次,覆盖了100个...
The Lottery Tickets Hypothesis for Supervised and Self-Supervised Pre-Training in Computer Vision Models
这是一个火车售票管理系统_train-tickets
【标题】"damai_tickets-master1.zip" 是一个与在线票务系统相关的代码仓库的压缩包,很可能包含了一个名为 "damai_tickets-master" 的项目源码。从名称来看,这个项目可能与大麦网(Damai)的票务系统有关,可能是...
SWP_Abstract_Ticket 摘要HÜ erzeugen Sie eine abstrakte Klassefür门票(体育,Konzert和剧院门票) Abzuspeichernde Informationen: 违规行为 普通名称 巴氏杆菌 票证 eine Methode berechneTicketpreis ...
例子屏幕截图显示了正在使用的CLI:安装 $ sudo npm install -g tickets选项输入tickets -h以查看选项: -d, --dir <value> directory to search in [default: process.cwd()]-e, --extensions <items> comma-...
(冀教版)五年级英语上册 Unit 4 Lesson 29 Buying Train Tickets 教案.doc
this source is used for those people who are far from their home to book a ticket easily.