首页 > 其他 > 详细

欧拉回路 fzu Problem 2112 Tickets

时间:2014-04-15 05:08:04      阅读:410      评论:0      收藏:0      [点我收藏+]

http://acm.fzu.edu.cn/problem.php?pid=2112

Problem 2112 Tickets

Accept: 229    Submit: 406
Time Limit: 3000 mSec    Memory Limit : 32768 KB

bubuko.com,布布扣 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.

bubuko.com,布布扣 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.

bubuko.com,布布扣 Output

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

bubuko.com,布布扣 Sample Input

35 31 31 24 56 51 31 21 61 51 43 21 21 2

bubuko.com,布布扣 Sample Output

120

bubuko.com,布布扣 Source

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

离散课上学过,欧拉通路 要么没有odd顶点,要么两个odd顶点,所以处理下就行了


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;
#define MAXN 100005

int degree[MAXN];

int main()
{
    int ncase,u,v,n,m,ans;

    scanf("%d",&ncase);

    while(ncase--)
    {
        memset(degree,0,sizeof(degree));
        scanf("%d%d",&n,&m);
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&u,&v);
            degree[u]++;
            degree[v]++;
        }
        ans=0;
        for(int i=0;i<=n;i++)
            ans+=degree[i]%2;
        ans=(ans-2)/2;
        ans<0?printf("0\n"):printf("%d\n",ans);
    }
    return 0;

}




欧拉回路 fzu Problem 2112 Tickets,布布扣,bubuko.com

欧拉回路 fzu Problem 2112 Tickets

原文:http://blog.csdn.net/u011026968/article/details/23693331

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!