FZU 2112【Tickets】

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


欧拉回路的应用


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
#define MAXN 100000 + 1000
int deep[MAXN];
int main()
{
    int t,m,n,i,u,v;
   scanf("%d",&t);
    while(t--)
    {
        memset(deep,0,sizeof(deep));
        scanf("%d%d",&m,&n);
        for(i=0; i<n; i++)
        {
            scanf("%d%d",&u,&v);
            deep[u]++;
            deep[v]++;
        }
        int sum=0;
        for(i=1; i<=m; i++)
            sum+=deep[i]%2;
        sum=(sum-2)/2;
        if(sum>0)
        printf("%d\n",sum);
        else printf("0\n");
    }


    return 0;
}


你可能感兴趣的:(FZU 2112【Tickets】)