FOJ FZU 2112 Tickets【欧拉通路】
来源:互联网 发布:影响二次销售 淘宝介入 编辑:程序博客网 时间:2024/05/16 13:28
Accept: 424 Submit: 731
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
题目大意:使用完所有飞机票,问最少购买额外的票数。
对于有票的路径和需要购买的票所构成的路径,最终要形成一个欧拉通路。
对于无向图的欧拉通路:图中形成的通路只有两个或者零个奇数度的点,换句话说:这个图最终能够形成欧拉路径或者是欧拉回路。
假设对于样例2
建图之后得到的奇数度的点为6,那么我们最贪心能够构成一条欧拉通路的奇数度的点为两个,这个时候我们需要连接四个度为奇数的点。相当于构建两条路径。
输出为(6-2)/2;
假设对于样例3
建图之后得到的奇数度的点为0,那么我们最贪心能够构成一条欧拉通路的奇数度的点为零个,这个时候直接输出0即可。
AC代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int degree[100005];int main(){ int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); memset(degree,0,sizeof(degree)); for(int i=0;i<m;i++) { int x,y; scanf("%d%d",&x,&y); degree[x]++;degree[y]++; } int cont=0; for(int i=1;i<=n;i++) { if(degree[i]%2==1)cont++; } if(cont>=2) printf("%d\n",(cont-2)/2); else printf("0\n"); }}
- FOJ FZU 2112 Tickets【欧拉通路】
- FZU 2112 Tickets (连通分量&欧拉通路)
- fzu 2112 Tickets(欧拉道路)
- 欧拉回路 fzu Problem 2112 Tickets
- 【欧拉路径】 FZU 2112 Tickets
- FZU 2112 Tickets(欧拉路径)
- 2112 fzu Tickets 欧拉路径
- FZU 2112(欧拉通路&&判联通图)
- FZU2112 Tickets (并查集+欧拉通路)经典
- fzu 2112 Tickets 图论
- FZU - 2112 Tickets
- FZU 2112【Tickets】
- FZU 2112K - Tickets
- 欧拉通路
- Euler(欧拉通路)
- hdu5883【欧拉通路】
- 欧拉通路、回路
- 欧拉通路
- java ThreadLocal及线程封闭
- 使用OAuth2的SSO分析
- 三极管开关电路设计
- poj 2549
- HDU:1878 欧拉回路(并查集+欧拉回路)
- FOJ FZU 2112 Tickets【欧拉通路】
- Hanoi塔问题
- Python Requests安装
- 文件读取的四种方式
- JFinal框架简单学习
- 第5周项目1 三角形4
- smdk210 构建根文件系统
- C语言编程在Xcode中Scanf 输入跳过以及清空键盘缓冲区总结
- 读取文件中的内容