Description
You are won a collection of tickets on luxury cruisers. Each ticket can is used only once, but can is used in either direction between the 2 different cities printed on the Ticke T. Your Prize gives you free airfare to all city to start Your cruising, and free airfare back home from wherever you fini SH your cruising.
Sail and Don ' t want to waste any of the your free tickets. How many additional tickets would are you having to buy so, your cruise can use all of your tickets?
Now giving the free tickets you have won. Please compute the smallest number of additional tickets so can be purchased-to-allow-all of your free ticket S.
Input
There is an 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 is between 1 and N, inclusive. M indicates the tickets you have won.
Then following m lines, each line contains the 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, indicates the smallest number of additional tickets you need to BU Y.
Sample Input
35 31 31 24 56 51 31 21 61 51 43 21 21 2
Sample Output
120 build, see a few tiles, then each tile is considered separately
#include <stdio.h> #include <algorithm> #include <iostream> #include <string.h> #include < String> #include <math.h>using namespace std; #define MAXN 100000 + 1000int VIS[MAXN],JIOU[MAXN][2],HEAD[MAXN], Du[maxn];int n,m;int tol;struct edge{int u,v,next;} Edge[maxn*2];void Addedge (int u,int v) {//Build edge[tol].u = u; EDGE[TOL].V = v; Edge[tol].next = Head[u]; head[u]=tol++; edge[tol].u = v; EDGE[TOL].V = u; Edge[tol].next = Head[v]; HEAD[V] = tol++;} void DFS (int u,int pre,int num) {vis[u] = 1; if (du[u]%2 = = 0) {jiou[num][0]++; } else{jiou[num][1]++; } for (int i=head[u];i!=-1;i=edge[i].next) {int v = EDGE[I].V; if (vis[v]==1 | | v==pre) {continue; } DFS (V,u,num); }}int Main () {int T; int A, B; while (~SCANF ("%d", &t)) {while (t--) {scanf ("%d%d", &n,&m); memset (head,-1,sizeof (head)); memset (vis,0,sizeof (VIS)); memset (jiou,0,sizeof (Jiou)); memset (du,0,sizeof (du)); Tol = 0; for (int i=0;i<m;i++) {scanf ("%d%d", &a,&b); Addedge (A, b); Addedge (B,a); du[a]++; du[b]++; } int s = 0;//has several tiles for (int i=0;i<n;i++) {if (vis[i]==0 && du[i]!=0) { DFS (i,-1,s++); }} int sum = s-1; for (int i=0;i<s;i++) {if (jiou[i][1] > 2) {sum+= (jiou[i][1]-2)/2; }} printf ("%d\n", sum); }} return 0;}
Build a map Fzu 2112