码迷,mamicode.com
首页 > 其他好文 > 详细

fzu 2112 tickets

时间:2018-04-21 15:21:09      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:compute   color   学生   scanf   one   namespace   欧拉   cst   contain   

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

For each test case, output an integer in a single line, indicates the smallest number of additional tickets you need to buy.

技术分享图片 Sample Input

3 5 3 1 3 1 2 4 5 6 5 1 3 1 2 1 6 1 5 1 4 3 2 1 2 1 2

技术分享图片 Sample Output

1 2 0

技术分享图片 Source

“高教社杯”第三届福建省大学生程序设计竞赛

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#define Max 100005///需要用完所有的票,完成巡游,另外要买的票来填补路线空缺,这样只能留下最多两个奇数顶点作为起点终点(可以是同一点),也就是欧拉路径
using namespace std;///只需要找出记录点个数(偶数个)-2,然后每两个多余的点,买一张票连接
int val[Max],a,b,n,m,T;
int main()
{
    scanf("%d",&T);
    while(T --)
    {
        int c = 0;
        scanf("%d%d",&n,&m);
        memset(val,0,sizeof(val));
        for(int i = 0;i < m;i ++)
        {
            scanf("%d%d",&a,&b);
            val[a] ++;
            val[b] ++;
        }
        for(int i = 1;i <= n;i ++)
        {
            if(val[i] % 2)c ++;
        }
        c = (c - 2) / 2;
        printf("%d\n",c < 0 ? 0 : c);
    }
}

 

fzu 2112 tickets

标签:compute   color   学生   scanf   one   namespace   欧拉   cst   contain   

原文地址:https://www.cnblogs.com/8023spz/p/8901156.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!